private NetTopologySuite.Features.Feature getFeature(ReferenceGeometry g, GeomType type) { List <Coordinate> coordinatesSwissGrid = new List <Coordinate>(); Coordinate[] coordinates; if (type == GeomType.Point) { coordinates = g.Point.Coordinates; } else if (type == GeomType.Line) { coordinates = g.Line.Coordinates; } else if (type == GeomType.Polygon) { coordinates = g.Polygon.Coordinates; } else { coordinates = null; } foreach (Coordinate coor in coordinates) { // Convert Coordinates to LV03 double x = 0, y = 0, h = 0; CoordinateConverter.WGS84toLV03(coor.Y, coor.X, 0, ref x, ref y, ref h); Coordinate newcoord = new Coordinate(x, y); coordinatesSwissGrid.Add(newcoord); } try { var gf = new GeometryFactory(); Geometry polygonSwissGrid = null; if (type == GeomType.Point) { polygonSwissGrid = gf.CreatePoint(coordinatesSwissGrid[0]); } else if (type == GeomType.Line) { polygonSwissGrid = gf.CreateLineString(coordinatesSwissGrid.ToArray()); } else if (type == GeomType.Polygon) { polygonSwissGrid = gf.CreatePolygon(coordinatesSwissGrid.ToArray()); } NetTopologySuite.Features.AttributesTable attribute = new NetTopologySuite.Features.AttributesTable(); attribute.Add("id", g.GeometryId); attribute.Add("name", g.GeometryName); NetTopologySuite.Features.Feature i = new NetTopologySuite.Features.Feature(polygonSwissGrid, attribute); return(i); } catch (Exception e) { return(null); } }
public static List <LPoints> GetGeometry(GeomType geomType, List <uint> geometryCommands) { List <LPoints> geomOut = new List <LPoints>(); LPoints geomTmp = new LPoints(); long cursorX = 0; long cursorY = 0; for (int i = 0; i < geometryCommands.Count; i++) { uint g = geometryCommands[i]; Commands cmd = (Commands)(g & 0x7); uint cmdCount = g >> 3; if (cmd == Commands.LineTo) { for (int j = 0; j < cmdCount; j++) { long x = geometryCommands[i + 1]; long y = geometryCommands[i + 2]; cursorX += (x >> 1) ^ -(x & 1); cursorY += (y >> 1) ^ -(y & 1); i += 2; if (cmd == Commands.MoveTo && geomTmp.Count > 0) { geomOut.Add(geomTmp); geomTmp.Clear(); } geomTmp.Add(new LPoint(cursorX, cursorY)); } } else if (cmd == Commands.MoveTo) { long x = geometryCommands[i + 1]; long y = geometryCommands[i + 2]; cursorX += (x >> 1) ^ -(x & 1); cursorY += (y >> 1) ^ -(y & 1); i += 2; if (geomTmp.Count > 0) { geomOut.Add(geomTmp); geomTmp.Clear(); } geomTmp.Add(new LPoint(cursorX, cursorY)); } else if (cmd == Commands.ClosePath && geomType == GeomType.POLYGON && geomTmp.Count > 0) { geomTmp.Add(geomTmp[0]); } } if (geomTmp.Count > 0) { geomOut.Add(geomTmp); } return(geomOut); }
// create a face based on input node private void CreateFaceGeometry(Node n, int name, GeomType type) { // default white Color color = new Color(1, 1, 1); switch (type) { case GeomType.Goal: color = Control.pathColor; break; case GeomType.Start: color = Control.pathColor; break; case GeomType.Path: color = Control.pathColor; break; } GameObject face = GameObject.CreatePrimitive(PrimitiveType.Plane); face.name = "face " + name; face.transform.position = n.position; face.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f); Renderer rend2 = face.GetComponent <Renderer>(); rend2.material.SetColor("_Color", color); GameObject container = GameObject.Find("Maze Geometry"); face.transform.SetParent(container.transform, true); }
/// <summary> /// <para>returns a list of lists.</para> /// <para>If the root list contains one child list it is a single part feature</para> /// <para>and the child list contains the coordinate pairs.</para> /// <para>e.g. single part point:</para> /// <para> Parent list with one child list, child list contains one Pont2D</para> /// <para>If the root list contains several child lists, it is a multipart feature</para> /// <para>e.g. multipart or donut polygon:</para> /// <para> Parent list contains number of list equal to the number of parts.</para> /// <para> Each child list contains the corrdinates of this part.</para> /// </summary> /// <param name="extent">Tile extent</param> /// <param name="geomType">Geometry type</param> /// <param name="geometryCommands">VT geometry commands, see spec</param> /// <param name="scale">factor for scaling internal tile coordinates</param> /// <returns>List<List<Point2d<long>>>> of decoded geometries (in internal tile coordinates)</returns> public static List <List <Point2d <long> > > GetGeometry( ulong extent , GeomType geomType , List <uint> geometryCommands , float scale = 1.0f ) { List <List <Point2d <long> > > geomOut = new List <List <Point2d <long> > >(); List <Point2d <long> > geomTmp = new List <Point2d <long> >(); long cursorX = 0; long cursorY = 0; // long tileExtent = (long)extent; for (int i = 0; i < geometryCommands.Count; i++) { uint g = geometryCommands[i]; Commands cmd = (Commands)(g & 0x7); uint cmdCount = g >> 3; if (cmd == Commands.MoveTo || cmd == Commands.LineTo) { for (int j = 0; j < cmdCount; j++) { Point2d <long> delta = zigzagDecode(geometryCommands[i + 1], geometryCommands[i + 2]); cursorX += delta.X; cursorY += delta.Y; i += 2; //end of part of multipart feature if (cmd == Commands.MoveTo && geomTmp.Count > 0) { geomOut.Add(geomTmp); geomTmp = new List <Point2d <long> >(); } //Point2d pntTmp = new Point2d(cursorX, cursorY); Point2d <long> pntTmp = new Point2d <long>() { X = cursorX, Y = cursorY }; geomTmp.Add(pntTmp); } } if (cmd == Commands.ClosePath) { if (geomType == GeomType.POLYGON && geomTmp.Count > 0) { geomTmp.Add(geomTmp[0]); } } } if (geomTmp.Count > 0) { geomOut.Add(geomTmp); } return(geomOut); }
private static List <LPoints> ClipGeometries(List <LPoints> geoms, GeomType geomType, long extent, uint bufferSize) { bool closed = geomType != GeomType.LINESTRING; List <LPoints> clip = new List <LPoints> { new LPoints { new LPoint(0L - bufferSize, 0L - bufferSize), new LPoint(extent + bufferSize, 0L - bufferSize), new LPoint(extent + bufferSize, extent + bufferSize), new LPoint(0L - bufferSize, extent + bufferSize) } }; List <LPoints> subjects = geoms.Select(g => new LPoints(g)).ToList(); OnlineMapsMapboxClipper.Clipper c = new OnlineMapsMapboxClipper.Clipper(); c.AddPaths(subjects, OnlineMapsMapboxClipper.PolyType.ptSubject, closed); c.AddPaths(clip, OnlineMapsMapboxClipper.PolyType.ptClip, true); List <LPoints> solution = new List <LPoints>(); bool succeeded; if (geomType == GeomType.LINESTRING) { OnlineMapsMapboxClipper.PolyTree lineSolution = new OnlineMapsMapboxClipper.PolyTree(); succeeded = c.Execute(OnlineMapsMapboxClipper.ClipType.ctIntersection, lineSolution, OnlineMapsMapboxClipper.PolyFillType.pftNonZero, OnlineMapsMapboxClipper.PolyFillType.pftNonZero); if (succeeded) { solution = OnlineMapsMapboxClipper.Clipper.PolyTreeToPaths(lineSolution); } } else { succeeded = c.Execute(OnlineMapsMapboxClipper.ClipType.ctIntersection, solution, OnlineMapsMapboxClipper.PolyFillType.pftNonZero, OnlineMapsMapboxClipper.PolyFillType.pftNonZero); } if (!succeeded) { return(geoms); } List <LPoints> retVal = new List <LPoints>(); foreach (LPoints part in solution) { LPoints p = new LPoints(part); if (geomType == GeomType.POLYGON && p[0] == p[p.Count - 1]) { p.Insert(0, p[p.Count - 1]); } retVal.Add(p); } return(retVal); }
/* * Constructors */ public RigidEntity(string id, Texture2D newTexture,ref PhysicsSimulator ps, GeomType newGeomType) : base(id) { texture = newTexture; geomType = newGeomType; preparePhysicsEntity(ps); physicsSim = ps; IsDrawable = true; }
public GType(GLib lib, GeomType geomType) { this.lib = lib; id = lib.GenerateId(this, ref updateAttr); priority = lib.LastPriority; this.geomType = geomType; lib.Add(this); lib.Register(this); }
public GType(GType parent) { lib = parent.Lib; id = lib.GenerateId(this, ref updateAttr); parentId = parent.Id; priority = parent.LastPriority; this.geomType = parent.geomType; this.parent = parent; parent.Add(this); lib.Register(this); }
GType GetType(GeomType gt) { foreach (GType type in lib.Types) { if (type.GeomType == gt) { return(type); } } return(null); }
/// <summary> /// TO BE REMOVED!!! Processing geometries is out of scope. /// Clip geometries extending beyond the tile border. /// </summary> /// <param name="geoms">Raw tile geometries of the feature</param> /// <param name="geomType">Geometry type of the feature</param> /// <param name="extent">Extent of the layer </param> /// <param name="bufferSize">Units (in internal tile coordinates) to go beyond the tile border. Pass '0' to clip exactly at the tile border</param> /// <param name="scale">Factor for scaling the geometries</param> /// <returns></returns> public static List <List <Point2d <long> > > ClipGeometries( List <List <Point2d <long> > > geoms , GeomType geomType , long extent , uint bufferSize , float scale ) { List <List <Point2d <long> > > retVal = new List <List <Point2d <long> > >(); return(null); }
/// <summary> /// Create a feature class /// </summary> /// <param name="dataset">Name of the feature class to be created.</param> /// <param name="featureclassType">Type of feature class to be created. Options are: /// <list type="bullet"> /// <item>POINT</item> /// <item>MULTIPOINT</item> /// <item>POLYLINE</item> /// <item>POLYGON</item></list></param> /// <param name="connection">connection path</param> /// <param name="spatialRef">SpatialReference</param> /// <param name="graphicsList">List of graphics</param> /// <param name="mapview">MapView object</param> /// <param name="isKML">Is this a kml output</param> /// <returns></returns> private static async Task CreateFeatureClass(string dataset, GeomType geomType, string connection, SpatialReference spatialRef, List <Graphic> graphicsList, MapView mapview, bool isKML = false) { try { string strGeomType = geomType == GeomType.PolyLine ? "POLYLINE" : "POLYGON"; List <object> arguments = new List <object>(); // store the results in the geodatabase arguments.Add(connection); // name of the feature class arguments.Add(dataset); // type of geometry arguments.Add(strGeomType); // no template arguments.Add(""); // no z values arguments.Add("DISABLED"); // no m values arguments.Add("DISABLED"); arguments.Add(spatialRef); //IReadOnlyList<string> valueArray = null; //await QueuedTask.Run(async () => //{ // valueArray = Geoprocessing.MakeValueArray(arguments.ToArray()); //}); //block the CIM for a second //Task.Delay(5000).Wait(); var valueArray = Geoprocessing.MakeValueArray(arguments.ToArray()); IGPResult result = await Geoprocessing.ExecuteToolAsync("CreateFeatureclass_management", valueArray); await CreateFeatures(graphicsList); if (isKML) { await KMLUtils.ConvertLayerToKML(connection, dataset, MapView.Active); // Delete temporary Shapefile string[] extensionNames = { ".cpg", ".dbf", ".prj", ".shx", ".shp" }; string datasetNoExtension = Path.GetFileNameWithoutExtension(dataset); foreach (string extension in extensionNames) { string shapeFile = Path.Combine(connection, datasetNoExtension + extension); File.Delete(shapeFile); } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
/// <summary> /// Method to use when you need to move a feedback line to a point /// This forces a new point to be used, sometimes this method projects the point to a different spatial reference /// </summary> /// <param name="point"></param> //internal void FeedbackMoveTo(IPoint point) //{ // if (feedback == null || point == null) // return; // feedback.MoveTo(new Point() { X = point.X, Y = point.Y, SpatialReference = point.SpatialReference }); //} /// <summary> /// Saves graphics to file gdb or shp file /// </summary> /// <param name="obj"></param> private async void OnSaveAs() { var dlg = new ProSaveAsFormatView(); dlg.DataContext = new ProSaveAsFormatViewModel(); var vm = dlg.DataContext as ProSaveAsFormatViewModel; GeomType geomType = GeomType.Polygon; if (dlg.ShowDialog() == true) { // Get the graphics list for the selected tab List <Graphic> typeGraphicsList = new List <Graphic>(); if (this is ProLinesViewModel) { typeGraphicsList = GraphicsList.Where(g => g.GraphicType == GraphicTypes.Line).ToList(); geomType = GeomType.PolyLine; } else if (this is ProCircleViewModel) { typeGraphicsList = GraphicsList.Where(g => g.GraphicType == GraphicTypes.Circle).ToList(); } else if (this is ProEllipseViewModel) { typeGraphicsList = GraphicsList.Where(g => g.GraphicType == GraphicTypes.Ellipse).ToList(); } else if (this is ProRangeViewModel) { typeGraphicsList = GraphicsList.Where(g => g.GraphicType == GraphicTypes.RangeRing).ToList(); geomType = GeomType.PolyLine; } string path = fcUtils.PromptUserWithSaveDialog(vm.FeatureIsChecked, vm.ShapeIsChecked, vm.KmlIsChecked); if (path != null) { try { string folderName = System.IO.Path.GetDirectoryName(path); if (vm.FeatureIsChecked) { await fcUtils.CreateFCOutput(path, SaveAsType.FileGDB, typeGraphicsList, MapView.Active.Map.SpatialReference, MapView.Active, geomType); } else if (vm.ShapeIsChecked || vm.KmlIsChecked) { await fcUtils.CreateFCOutput(path, SaveAsType.Shapefile, typeGraphicsList, MapView.Active.Map.SpatialReference, MapView.Active, geomType, vm.KmlIsChecked); } } catch (Exception ex) { } } } }
/* public static bool IsVisibleOnMap(IShapedObject obj,Map map) * { * if(!obj.IsVisibleOnMap(map)) return false; * if(obj.Parent==null) return true; * return IsVisibleOnMap(obj.Parent,map); * }*/ public static string GetLocalizedName(GeomType gt) { switch (gt) { case GeomType.Caption: return(Locale.Get("gtcaption")); case GeomType.Point: return(Locale.Get("gtpoint")); case GeomType.Polygon: return(Locale.Get("gtpolygon")); case GeomType.Polyline: return(Locale.Get("gtpolyline")); } return(gt.ToString()); }
public GeomLayer(GeomType type = GeomType.Point, string name = "矢量图层") : base(name) { if (type >= GeomType.Point) { points = new List <GeomPoint>(); } if (type >= GeomType.Arc) { arcs = new List <GeomArc>(); } if (type == GeomType.Polygon) { polygons = new List <GeomPoly>(); } }
internal GType(Context context, IDataReader dr) { this.lib = context.Lib; id = dr.GetInt32((int)TypeField.Id); parentId = dr.GetInt32((int)TypeField.ParentId); priority = dr.GetInt32((int)TypeField.Priority); attr = dr.GetInt32((int)TypeField.Attr); name = dr.GetString((int)TypeField.Name); // DZ 16.01.09 // context.SetStyle(dr.GetString(((int)TypeField.Style)),ref styleStr,ref style); context.SetStyle( dr.IsDBNull((int)TypeField.Style) ? "" : dr.GetString((int)TypeField.Style), ref styleStr, ref style); geomType = (GeomType)dr.GetInt32((int)TypeField.GeomType); smin = dr.GetInt32((int)TypeField.SMin); smax = dr.GetInt32((int)TypeField.SMax); lib.Register(this); }
static string convertGeometryType(GeomType type) { if (type == GeomType.LINESTRING) { return("LineString"); } else if (type == GeomType.POINT) { return("Point"); } else if (type == GeomType.POLYGON) { return("Polygon"); } else { return("Unknown"); } }
internal GType(Context context, BinaryReader br) { this.lib = context.Lib; id = br.ReadInt32(); // lib.UpdateGen(this); parentId = br.ReadInt32(); priority = br.ReadInt32(); attr = br.ReadInt32(); name = br.ReadString(); context.SetStyle(br.ReadString(), ref styleStr, ref style); geomType = (GeomType)br.ReadInt32(); smin = br.ReadInt32(); smax = br.ReadInt32(); if (parentId != 0) { parent = lib.GetType(parentId); } this.ParentComposite.Add(this); lib.Register(this); }
void AddType() { TreeNode selNode = this.SelectedNode; if (selNode == null) { return; } GComposite comp = this.SelectedComposite; GType type = null; if (comp is GLib) { TypeForm form = new TypeForm(); if (form.ShowDialog() == DialogResult.OK && form.geomType is GeomType) { GeomType gt = (GeomType)form.geomType; type = new GType(comp as GLib, gt); } } else if (comp is GType) { GType parType = (GType)comp; type = new GType(parType); } if (type != null) { GenerateDefaultTypeName(type); if (app.GetControlsAttr(ControlsAttr.AutoSave)) { using (Context context = Lib.GetContext()) type.Save(context); } AppLayer.Add(type.Id); TreeNode node = AddNode(selNode, type); this.tvTypes.SelectedNode = node; if (OnTypeAdded != null) { OnTypeAdded(this, new TypeEventArgs(type)); } } }
public Geometry(IEnumerable<Vector3> points, GeomType gType) { this.Points = points.ToList(); this.geomType = gType; switch (gType) { case GeomType.Floor: { vb = new VertexBuffer(G.g.GraphicsDevice, typeof(VertexPositionNormalTexture), 6, BufferUsage.WriteOnly); vb.SetData<VertexPositionNormalTexture>(points.Select(x => new VertexPositionNormalTexture(x, Vector3.Up, new Vector2(x.X / 4, x.Z / 4))).Concat( points.Reverse().Select(x => new VertexPositionNormalTexture(new Vector3(x.X, 24, x.Z), Vector3.Down, new Vector2(x.X / 4, x.Z / 4))) ).ToArray()); } break; case GeomType.Wall: { vb = new VertexBuffer(G.g.GraphicsDevice, typeof(VertexPositionNormalTexture), 6, BufferUsage.WriteOnly); var result = new List<VertexPositionNormalTexture>(); var a = points.First(); var b = points.Skip(1).First(); var scale = 4; var length = (b - a).Length() / scale; result.Add(new VertexPositionNormalTexture(a, Vector3.Cross(a, b), new Vector2(0, 0))); result.Add(new VertexPositionNormalTexture(b + new Vector3(0, 24, 0), Vector3.Cross(a, b), new Vector2(8, length))); result.Add(new VertexPositionNormalTexture(b, Vector3.Cross(a, b), new Vector2(0, length))); result.Add(new VertexPositionNormalTexture(a + new Vector3(0, 24, 0), Vector3.Cross(a, b), new Vector2(8, 0))); result.Add(new VertexPositionNormalTexture(b + new Vector3(0, 24, 0), Vector3.Cross(a, b), new Vector2(8, length))); result.Add(new VertexPositionNormalTexture(a, Vector3.Cross(a, b), new Vector2(0, 0))); vb.SetData<VertexPositionNormalTexture>(result.ToArray()); } break; default: throw new Exception(); } }
public StyleControl(DBTablesGroups par, propertyTableControl p_table, GeomType type, bool canWrite = true) { InitializeComponent(); btnOk.Enabled = canWrite; tb1 = new TabControl(); loadPenList(); loadImgBrush(); foreach (FontFamily ff in FontFamily.Families) { if (ff.Name.Equals("Map Symbols", StringComparison.InvariantCultureIgnoreCase)) { fontDialog1.Font = new Font("Map Symbols", 14); loadSymbol(); } } showTabPanel(true, true, true); parent = par; property_table = p_table; TabPage symbPage = tabControl1.TabPages[0]; TabPage penPage = tabControl1.TabPages[1]; TabPage brushPage = tabControl1.TabPages[2]; if (type == GeomType.point) { tabControl1.TabPages.Remove(penPage); tabControl1.TabPages.Remove(brushPage); } else if (type == GeomType.line) { tabControl1.TabPages.Remove(symbPage); tabControl1.TabPages.Remove(brushPage); } else if (type == GeomType.polygon) { tabControl1.TabPages.Remove(symbPage); } }
/// <summary> /// TO BE REMOVED!!! Processing geometries is out of scope. /// Clip geometries extending beyond the tile border. /// </summary> /// <param name="geoms">Raw tile geometries of the feature</param> /// <param name="geomType">Geometry type of the feature</param> /// <param name="extent">Extent of the layer </param> /// <param name="bufferSize">Units (in internal tile coordinates) to go beyond the tile border. Pass '0' to clip exactly at the tile border</param> /// <param name="scale">Factor for scaling the geometries</param> /// <returns></returns> public static List <List <Point2d <long> > > ClipGeometries( List <List <Point2d <long> > > geoms , GeomType geomType , long extent , uint bufferSize , float scale ) { List <List <Point2d <long> > > retVal = new List <List <Point2d <long> > >(); //points: simply remove them if one part of the coordinate pair is out of bounds: // <0 || >extent if (geomType == GeomType.POINT) { foreach (var geomPart in geoms) { List <Point2d <long> > outGeom = new List <Point2d <long> >(); foreach (var geom in geomPart) { if ( geom.X < (0L - bufferSize) || geom.Y < (0L - bufferSize) || geom.X > (extent + bufferSize) || geom.Y > (extent + bufferSize) ) { continue; } outGeom.Add(geom); } if (outGeom.Count > 0) { retVal.Add(outGeom); } } return(retVal); } //use clipper for lines and polygons bool closed = true; if (geomType == GeomType.LINESTRING) { closed = false; } Polygons subjects = new Polygons(); Polygons clip = new Polygons(1); Polygons solution = new Polygons(); clip.Add(new Polygon(4)); clip[0].Add(new InternalClipper.IntPoint(0L - bufferSize, 0L - bufferSize)); clip[0].Add(new InternalClipper.IntPoint(extent + bufferSize, 0L - bufferSize)); clip[0].Add(new InternalClipper.IntPoint(extent + bufferSize, extent + bufferSize)); clip[0].Add(new InternalClipper.IntPoint(0L - bufferSize, extent + bufferSize)); foreach (var geompart in geoms) { Polygon part = new Polygon(); foreach (var geom in geompart) { part.Add(new InternalClipper.IntPoint(geom.X, geom.Y)); } subjects.Add(part); } InternalClipper.Clipper c = new InternalClipper.Clipper(); c.AddPaths(subjects, InternalClipper.PolyType.ptSubject, closed); c.AddPaths(clip, InternalClipper.PolyType.ptClip, true); bool succeeded = false; if (geomType == GeomType.LINESTRING) { InternalClipper.PolyTree lineSolution = new InternalClipper.PolyTree(); succeeded = c.Execute( InternalClipper.ClipType.ctIntersection , lineSolution , InternalClipper.PolyFillType.pftNonZero , InternalClipper.PolyFillType.pftNonZero ); if (succeeded) { solution = InternalClipper.Clipper.PolyTreeToPaths(lineSolution); } } else { succeeded = c.Execute( InternalClipper.ClipType.ctIntersection , solution , InternalClipper.PolyFillType.pftNonZero , InternalClipper.PolyFillType.pftNonZero ); } if (succeeded) { retVal = new List <List <Point2d <long> > >(); foreach (var part in solution) { List <Point2d <long> > geompart = new List <Point2d <long> >(); // HACK: // 1. clipper may or may not reverse order of vertices of LineStrings // 2. clipper semms to drop the first vertex of a Polygon // * We don't care about 1. // * Added a check for 2 and insert a copy of last vertex as first foreach (var geom in part) { geompart.Add(new Point2d <long>() { X = geom.X, Y = geom.Y }); } if (geomType == GeomType.POLYGON) { if (!geompart[0].Equals(geompart[geompart.Count - 1])) { geompart.Insert(0, geompart[geompart.Count - 1]); } } retVal.Add(geompart); } return(retVal); } else { //if clipper was not successfull return original geometries return(geoms); } }
// todo: create a cube based on input node private void CreateCubeGeometry(Node n, int name, GeomType type) { // default white Color color = new Color(1, 1, 1); switch (type) { case GeomType.Goal: color = Control.pathColor; break; case GeomType.Start: color = Control.pathColor; break; case GeomType.Path: color = Control.pathColor; break; } GameObject f1 = GameObject.CreatePrimitive(PrimitiveType.Plane); f1.name = "nodeFace"; f1.transform.position = n.position; f1.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f); Renderer r1 = f1.GetComponent <Renderer>(); r1.material.SetColor("_Color", color); GameObject container = GameObject.Find("Maze Geometry"); f1.transform.SetParent(container.transform, true); GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube); cube.name = "cube " + name; Renderer r2 = cube.GetComponent <Renderer>(); r2.material.SetColor("_Color", color); cube.transform.SetParent(f1.transform, true); if (n.up.Equals(posY)) { cube.transform.position = n.position + negY * 0.5f; } else if (n.up.Equals(negX)) { cube.transform.position = n.position + negY * 0.5f; f1.transform.eulerAngles = new Vector3(f1.transform.eulerAngles.x, // so it will face -x f1.transform.eulerAngles.y, f1.transform.eulerAngles.z + 90); } else if (n.up.Equals(negZ)) { cube.transform.position = n.position + negY * 0.5f; f1.transform.eulerAngles = new Vector3(f1.transform.eulerAngles.x - 90, f1.transform.eulerAngles.y, f1.transform.eulerAngles.z); } else { Debug.Log("Warning: invalid normal"); return; } }
/// <summary> /// Creates the output featureclass, either fgdb featureclass or shapefile /// </summary> /// <param name="outputPath">location of featureclass</param> /// <param name="saveAsType">Type of output selected, either fgdb featureclass or shapefile</param> /// <param name="graphicsList">List of graphics for selected tab</param> /// <param name="ipSpatialRef">Spatial Reference being used</param> /// <returns>Output featureclass</returns> public async Task CreateFCOutput(string outputPath, SaveAsType saveAsType, List<Graphic> graphicsList, SpatialReference spatialRef, MapView mapview, GeomType geomType, bool isKML = false) { string dataset = System.IO.Path.GetFileName(outputPath); string connection = System.IO.Path.GetDirectoryName(outputPath); try { await QueuedTask.Run(async () => { await CreateFeatureClass(dataset, geomType, connection, spatialRef, graphicsList, mapview, isKML); }); } catch (Exception ex) { } }
/// <summary> /// Create a feature class /// </summary> /// <param name="dataset">Name of the feature class to be created.</param> /// <param name="featureclassType">Type of feature class to be created. Options are: /// <list type="bullet"> /// <item>POINT</item> /// <item>MULTIPOINT</item> /// <item>POLYLINE</item> /// <item>POLYGON</item></list></param> /// <param name="connection">connection path</param> /// <param name="spatialRef">SpatialReference</param> /// <param name="graphicsList">List of graphics</param> /// <param name="mapview">MapView object</param> /// <param name="isKML">Is this a kml output</param> /// <returns></returns> private static async Task CreateFeatureClass(string dataset, GeomType geomType, string connection, SpatialReference spatialRef, List <Graphic> graphicsList, MapView mapview, bool isKML = false) { try { List <Graphic> list = ClearTempGraphics(graphicsList); if ((list == null) || (list.Count == 0)) { return; } string strGeomType = geomType == GeomType.PolyLine ? "POLYLINE" : "POLYGON"; List <object> arguments = new List <object>(); // store the results in the geodatabase arguments.Add(connection); // name of the feature class arguments.Add(dataset); // type of geometry arguments.Add(strGeomType); // no template arguments.Add(null); // no m values arguments.Add("DISABLED"); // no z values arguments.Add("DISABLED"); arguments.Add(spatialRef.Wkid.ToString()); // store the results in the geodatabase object[] argArray = arguments.ToArray(); var environments = Geoprocessing.MakeEnvironmentArray(overwriteoutput: true); //var valueArray = Geoprocessing.MakeValueArray(argArray); IGPResult result = await Geoprocessing.ExecuteToolAsync("CreateFeatureclass_management", Geoprocessing.MakeValueArray(argArray), environments, null, null); // Add additional fields based on type of graphic string nameNoExtension = Path.GetFileNameWithoutExtension(dataset); string featureClass = ""; if (isKML) { featureClass = connection + "/" + nameNoExtension + ".shp"; } else { featureClass = connection + "/" + dataset; } string graphicsType = list[0].p.GetType().ToString().Replace("ProAppDistanceAndDirectionModule.", ""); switch (graphicsType) { case "LineAttributes": { IGPResult result2 = await Geoprocessing.ExecuteToolAsync("AddField_management", makeValueArray(featureClass, "Distance", "DOUBLE")); IGPResult result3 = await Geoprocessing.ExecuteToolAsync("AddField_management", makeValueArray(featureClass, "DistUnit", "TEXT")); IGPResult result4 = await Geoprocessing.ExecuteToolAsync("AddField_management", makeValueArray(featureClass, "OriginX", "DOUBLE")); IGPResult result5 = await Geoprocessing.ExecuteToolAsync("AddField_management", makeValueArray(featureClass, "OriginY", "DOUBLE")); IGPResult result6 = await Geoprocessing.ExecuteToolAsync("AddField_management", makeValueArray(featureClass, "DestX", "DOUBLE")); IGPResult result7 = await Geoprocessing.ExecuteToolAsync("AddField_management", makeValueArray(featureClass, "DestY", "DOUBLE")); IGPResult result8 = await Geoprocessing.ExecuteToolAsync("AddField_management", makeValueArray(featureClass, "Angle", "DOUBLE")); IGPResult result9 = await Geoprocessing.ExecuteToolAsync("AddField_management", makeValueArray(featureClass, "AngleUnit", "TEXT")); break; } case "CircleAttributes": { IGPResult result2 = await Geoprocessing.ExecuteToolAsync("AddField_management", makeValueArray(featureClass, "Distance", "DOUBLE")); IGPResult result3 = await Geoprocessing.ExecuteToolAsync("AddField_management", makeValueArray(featureClass, "DistUnit", "TEXT")); IGPResult result4 = await Geoprocessing.ExecuteToolAsync("AddField_management", makeValueArray(featureClass, "DistType", "TEXT")); IGPResult result5 = await Geoprocessing.ExecuteToolAsync("AddField_management", makeValueArray(featureClass, "CenterX", "DOUBLE")); IGPResult result6 = await Geoprocessing.ExecuteToolAsync("AddField_management", makeValueArray(featureClass, "CenterY", "DOUBLE")); break; } case "EllipseAttributes": { IGPResult result2 = await Geoprocessing.ExecuteToolAsync("AddField_management", makeValueArray(featureClass, "Minor", "DOUBLE")); IGPResult result3 = await Geoprocessing.ExecuteToolAsync("AddField_management", makeValueArray(featureClass, "Major", "DOUBLE")); IGPResult result4 = await Geoprocessing.ExecuteToolAsync("AddField_management", makeValueArray(featureClass, "DistUnit", "TEXT")); IGPResult result5 = await Geoprocessing.ExecuteToolAsync("AddField_management", makeValueArray(featureClass, "CenterX", "DOUBLE")); IGPResult result6 = await Geoprocessing.ExecuteToolAsync("AddField_management", makeValueArray(featureClass, "CenterY", "DOUBLE")); IGPResult result7 = await Geoprocessing.ExecuteToolAsync("AddField_management", makeValueArray(featureClass, "Angle", "DOUBLE")); IGPResult result8 = await Geoprocessing.ExecuteToolAsync("AddField_management", makeValueArray(featureClass, "AngleUnit", "TEXT")); break; } case "RangeAttributes": { IGPResult result2 = await Geoprocessing.ExecuteToolAsync("AddField_management", makeValueArray(featureClass, "Rings", "LONG")); IGPResult result3 = await Geoprocessing.ExecuteToolAsync("AddField_management", makeValueArray(featureClass, "Distance", "DOUBLE")); IGPResult result4 = await Geoprocessing.ExecuteToolAsync("AddField_management", makeValueArray(featureClass, "DistUnit", "TEXT")); IGPResult result5 = await Geoprocessing.ExecuteToolAsync("AddField_management", makeValueArray(featureClass, "Radials", "LONG")); IGPResult result6 = await Geoprocessing.ExecuteToolAsync("AddField_management", makeValueArray(featureClass, "CenterX", "DOUBLE")); IGPResult result7 = await Geoprocessing.ExecuteToolAsync("AddField_management", makeValueArray(featureClass, "CenterY", "DOUBLE")); break; } } await CreateFeatures(list, isKML); if (isKML) { await KMLUtils.ConvertLayerToKML(connection, dataset, MapView.Active); // Delete temporary Shapefile string[] extensionNames = { ".cpg", ".dbf", ".prj", ".shx", ".shp", ".sbn", ".sbx" }; string datasetNoExtension = Path.GetFileNameWithoutExtension(dataset); foreach (string extension in extensionNames) { string shapeFile = Path.Combine(connection, datasetNoExtension + extension); string shapefileproj = Path.Combine(connection, datasetNoExtension + "_proj" + extension); if (File.Exists(shapeFile)) { File.Delete(shapeFile); } if (File.Exists(shapefileproj)) { File.Delete(shapefileproj); } } DirectoryInfo dir = new DirectoryInfo(connection); FileSystemInfo fsi = dir; fsi.Refresh(); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
/// <summary> /// Creates the output featureclass, either fgdb featureclass or shapefile /// </summary> /// <param name="outputPath">location of featureclass</param> /// <param name="saveAsType">Type of output selected, either fgdb featureclass or shapefile</param> /// <param name="graphicsList">List of graphics for selected tab</param> /// <param name="ipSpatialRef">Spatial Reference being used</param> /// <returns>Output featureclass</returns> public async Task CreateFCOutput(string outputPath, SaveAsType saveAsType, List <Graphic> graphicsList, SpatialReference spatialRef, MapView mapview, GeomType geomType, bool isKML = false) { string dataset = System.IO.Path.GetFileName(outputPath); string connection = System.IO.Path.GetDirectoryName(outputPath); try { await QueuedTask.Run(async() => { await CreateFeatureClass(dataset, geomType, connection, spatialRef, graphicsList, mapview, isKML); }); } catch (Exception ex) { } }
public RigidEntity(string id, ref PhysicsSimulator ps, Vector2 position, int width, int height) : base(id) { //Create an invisible rectangle phys object geomType = GeomType.Rectangle; body = BodyFactory.Instance.CreateRectangleBody(ps,(float)width, (float)height,1); geom = GeomFactory.Instance.CreateRectangleGeom(ps,body, (float)width, (float)height); Position = position; IsStatic = true; IsDrawable = false; }
GType CreateType(GeomType gt) { GType par = GetType(gt); return(new GType(par)); }
public RigidEntity(ContentManager cm, ref PhysicsSimulator phs, string xmlFileName) : base("FILE") { physicsSim = phs; //Stream stream = File.OpenRead(System.IO.Directory.GetCurrentDirectory()+"\\"+xmlFileName); //XmlSerializer xml = new XmlSerializer(typeof(StructRigidEntity)); //StructRigidEntity re = (StructRigidEntity)xml.Deserialize(stream); StructRigidEntity re = new StructRigidEntity(); re = cm.Load<StructRigidEntity>(xmlFileName); texture = cm.Load<Texture2D>(re.textureName); geomType = re.gType; preparePhysicsEntity(phs); IsDrawable = true; Friction = re.friction; Restitution = re.restitution; ID = re.name; //stream.Close(); }
/// <summary> /// 创建简单要素类 /// </summary> /// <param name="layerName">要素类名</param> /// <param name="geomType">几何类型,枚举</param> /// <param name="gdbName">打开的地理数据库名</param> public static bool CreateXClass(string layerName, GeomType geomType, string gdbName, string[] fields) { //方法:指定类型、数据集ID,空间参考系,创建类 Server svr = new Server(); SFeatureCls sfcls = null; //连接数据源,打开数据库 bool rtn = svr.Connect("MapGISLocal", "", ""); if (rtn == true) { DataBase gdb = svr.OpenGDB(gdbName); //打开简单要素类 sfcls = gdb.GetXClass(XClsType.SFCls) as SFeatureCls; //创建区类型的简单要素类 int id = sfcls.Create(layerName, geomType, 0, 0, null); if (id <= 0) { //关闭类、数据库、断开数据源 sfcls.Close(); gdb.Close(); svr.DisConnect(); return(false); } sfcls.Open(layerName, 0); Fields temp = sfcls.Fields; if (temp == null) { temp = new Fields(); } //Field adding = null; #region 添加属性 //1: successful 0: failed int result = temp.AppendField(new Field { FieldName = "DataID", FieldLength = 255, FieldType = FieldType.FldString, Editable = 1, MskLength = 15 }); result = temp.AppendField(new Field { FieldName = "BikeID", FieldLength = 255, FieldType = FieldType.FldString, Editable = 1, MskLength = 15 }); result = temp.AppendField(new Field { FieldName = "ParkTime", FieldType = FieldType.FldTime, Editable = 1, FieldLength = 10, MskLength = 10 }); result = temp.AppendField(new Field { FieldName = "Date", FieldType = FieldType.FldTime, Editable = 1, FieldLength = 10, MskLength = 10 }); result = temp.AppendField(new Field { FieldName = "xAsis", FieldLength = 255, FieldType = FieldType.FldDouble, Editable = 1, MskLength = 15 }); result = temp.AppendField(new Field { FieldName = "yAsis", FieldLength = 255, FieldType = FieldType.FldDouble, Editable = 1, MskLength = 15 }); #endregion //foreach (var item in fields) //{ // adding = new Field // { // FieldName = item, // FieldLength = 255, // FieldType = FieldType.FldString, // Editable = 1, // MskLength = 15 // }; // int result = temp.AppendField(adding); //1: successful 0: failed //} sfcls.Fields = temp; //关闭类、数据库、断开数据源 sfcls.Close(); gdb.Close(); svr.DisConnect(); if (id > 0) { return(true); } else { return(false); } } else { return(false); } }
/// <summary> /// Convert Mapbox tile format (see https://www.mapbox.com/vector-tiles/specification/) /// </summary> /// <param name="geom">Geometry information in Mapbox format</param> /// <param name="geomType">GeometryType of this geometry</param> /// <param name="scale">Factor for scaling of coordinates because of overzooming</param> /// <param name="offsetX">Offset in X direction because of overzooming</param> /// <param name="offsetY">Offset in Y direction because of overzooming</param> /// <returns>List of list of points in world coordinates</returns> public static List <List <Coordinate> > ParseGeometry(List <uint> geom, GeomType geomType, Overzoom overzoom, float scale) { const uint cmdMoveTo = 1; //const uint cmdLineTo = 2; const uint cmdSegEnd = 7; //const uint cmdBits = 3; long x = 0; long y = 0; var coordsList = new List <List <Coordinate> >(); List <Coordinate> coords = null; var geometryCount = geom.Count; uint length = 0; uint command = 0; var i = 0; while (i < geometryCount) { if (length <= 0) { length = geom[i++]; command = length & ((1 << 3) - 1); length = length >> 3; } if (length > 0) { if (command == cmdMoveTo) { coords = new List <Coordinate>(); coordsList.Add(coords); } } if (command == cmdSegEnd) { if (geomType != GeomType.Point && coords?.Count != 0) { coords?.Add(coords[0]); } length--; continue; } var dx = geom[i++]; var dy = geom[i++]; length--; var ldx = ZigZag.Decode(dx); var ldy = ZigZag.Decode(dy); x = x + ldx; y = y + ldy; // Correct coordinates for overzoom var coord = new Coordinate((x * overzoom.Scale - overzoom.OffsetX) * scale, (y * overzoom.Scale - overzoom.OffsetY) * scale); coords?.Add(coord); } return(coordsList); }
/// <summary> /// Create a feature class /// </summary> /// <param name="dataset">Name of the feature class to be created.</param> /// <param name="featureclassType">Type of feature class to be created. Options are: /// <list type="bullet"> /// <item>POINT</item> /// <item>MULTIPOINT</item> /// <item>POLYLINE</item> /// <item>POLYGON</item></list></param> /// <param name="connection">connection path</param> /// <param name="spatialRef">SpatialReference</param> /// <param name="graphicsList">List of graphics</param> /// <param name="mapview">MapView object</param> /// <param name="isKML">Is this a kml output</param> /// <returns></returns> private static async Task CreateFeatureClass(string dataset, GeomType geomType, string connection, SpatialReference spatialRef, List<Graphic> graphicsList, MapView mapview, bool isKML = false) { try { string strGeomType = geomType == GeomType.PolyLine ? "POLYLINE" : "POLYGON"; List<object> arguments = new List<object>(); // store the results in the geodatabase arguments.Add(connection); // name of the feature class arguments.Add(dataset); // type of geometry arguments.Add(strGeomType); // no template arguments.Add(""); // no z values arguments.Add("DISABLED"); // no m values arguments.Add("DISABLED"); arguments.Add(spatialRef); //IReadOnlyList<string> valueArray = null; //await QueuedTask.Run(async () => //{ // valueArray = Geoprocessing.MakeValueArray(arguments.ToArray()); //}); //block the CIM for a second //Task.Delay(5000).Wait(); var valueArray = Geoprocessing.MakeValueArray(arguments.ToArray()); IGPResult result = await Geoprocessing.ExecuteToolAsync("CreateFeatureclass_management", valueArray); await CreateFeatures(graphicsList); if (isKML) { await KMLUtils.ConvertLayerToKML(connection, dataset, MapView.Active); // Delete temporary Shapefile string[] extensionNames = {".cpg", ".dbf", ".prj", ".shx", ".shp"}; string datasetNoExtension = Path.GetFileNameWithoutExtension(dataset); foreach (string extension in extensionNames) { string shapeFile = Path.Combine(connection, datasetNoExtension + extension); File.Delete(shapeFile); } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
private static List <List <Point2d> > clipGeometries( List <List <Point2d> > geoms , GeomType geomType , long extent , uint bufferSize ) { List <List <Point2d> > retVal = new List <List <Point2d> >(); //points: simply remove them if one part of the coordinate pair is out of bounds: // <0 || >extent if (geomType == GeomType.POINT) { foreach (var geomPart in geoms) { List <Point2d> outGeom = new List <Point2d>(); foreach (var geom in geomPart) { if ( geom.X < (0L - bufferSize) || geom.Y < (0L - bufferSize) || geom.X > (extent + bufferSize) || geom.Y > (extent + bufferSize) ) { continue; } outGeom.Add(geom); } if (outGeom.Count > 0) { retVal.Add(outGeom); } } return(retVal); } //use clipper for lines and polygons bool closed = true; if (geomType == GeomType.LINESTRING) { closed = false; } Polygons subjects = new Polygons(); Polygons clip = new Polygons(1); Polygons solution = new Polygons(); clip.Add(new Polygon(4)); clip[0].Add(new InternalClipper.IntPoint(0L - bufferSize, 0L - bufferSize)); clip[0].Add(new InternalClipper.IntPoint(extent + bufferSize, 0L - bufferSize)); clip[0].Add(new InternalClipper.IntPoint(extent + bufferSize, extent + bufferSize)); clip[0].Add(new InternalClipper.IntPoint(0L - bufferSize, extent + bufferSize)); foreach (var geompart in geoms) { Polygon part = new Polygon(); foreach (var geom in geompart) { part.Add(new InternalClipper.IntPoint(geom.X, geom.Y)); } subjects.Add(part); } InternalClipper.Clipper c = new InternalClipper.Clipper(); c.AddPaths(subjects, InternalClipper.PolyType.ptSubject, closed); c.AddPaths(clip, InternalClipper.PolyType.ptClip, true); bool succeeded = false; if (geomType == GeomType.LINESTRING) { InternalClipper.PolyTree lineSolution = new InternalClipper.PolyTree(); succeeded = c.Execute( InternalClipper.ClipType.ctIntersection , lineSolution , InternalClipper.PolyFillType.pftNonZero , InternalClipper.PolyFillType.pftNonZero ); if (succeeded) { solution = InternalClipper.Clipper.PolyTreeToPaths(lineSolution); } } else { succeeded = c.Execute( InternalClipper.ClipType.ctIntersection , solution , InternalClipper.PolyFillType.pftNonZero , InternalClipper.PolyFillType.pftNonZero ); } if (succeeded) { retVal = new List <List <Point2d> >(); foreach (var part in solution) { List <Point2d> geompart = new List <Point2d>(); foreach (var geom in part) { geompart.Add(new Point2d() { X = geom.X, Y = geom.Y }); } retVal.Add(geompart); } return(retVal); } else { //if clipper was not successfull return original geometries return(geoms); } }
public async Task CreateFCOutput(string outputPath, SaveAsType saveAsType, List <CCProGraphic> mapPointList, SpatialReference spatialRef, MapView mapview, GeomType geomType, bool isKML = false) { string dataset = System.IO.Path.GetFileName(outputPath); string connection = System.IO.Path.GetDirectoryName(outputPath); try { await QueuedTask.Run(async() => { await CreateFeatureClass(dataset, connection, spatialRef, mapPointList, mapview, isKML); }); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } }