public static void main(string[] args) { ExtendedCoordinateSequenceFactory seqFact = ExtendedCoordinateSequenceFactory.Instance(); ExtendedCoordinate[] array1 = new ExtendedCoordinate[] { new ExtendedCoordinate(0, 0, 0, 91), new ExtendedCoordinate(10, 0, 0, 92), new ExtendedCoordinate(10, 10, 0, 93), new ExtendedCoordinate(0, 10, 0, 94), new ExtendedCoordinate(0, 0, 0, 91)}; ICoordinateSequence seq1 = seqFact.Create(array1); ICoordinateSequence seq2 = seqFact.Create(new ExtendedCoordinate[] { new ExtendedCoordinate(5, 5, 0, 91), new ExtendedCoordinate(15, 5, 0, 92), new ExtendedCoordinate(15, 15, 0, 93), new ExtendedCoordinate(5, 15, 0, 94), new ExtendedCoordinate(5, 5, 0, 91)}); GeometryFactory fact = new GeometryFactory(ExtendedCoordinateSequenceFactory.Instance()); IGeometry g1 = fact.CreatePolygon(fact.CreateLinearRing(seq1), null); IGeometry g2 = fact.CreatePolygon(fact.CreateLinearRing(seq2), null); Console.WriteLine("WKT for g1: " + g1); Console.WriteLine("Internal rep for g1: " + ((IPolygon) g1).ExteriorRing.CoordinateSequence); Console.WriteLine("WKT for g2: " + g2); Console.WriteLine("Internal rep for g2: " + ((IPolygon)g2).ExteriorRing.CoordinateSequence); IGeometry gInt = g1.Intersection(g2); Console.WriteLine("WKT for gInt: " + gInt); Console.WriteLine("Internal rep for gInt: " + ((IPolygon)gInt).ExteriorRing.CoordinateSequence); }
private void LoadParcels(List<PointD> pt, Color color, string labelname) { SharpMap.Map map = new SharpMap.Map(); List<GeoAPI.Geometries.Coordinate> vertices = new List<GeoAPI.Geometries.Coordinate>(); foreach (PointD i in pt) { GeoAPI.Geometries.Coordinate p = new GeoAPI.Geometries.Coordinate(); p.X = i.X; p.Y = i.Y; vertices.Add(p); } GeoAPI.Geometries.Coordinate l = new GeoAPI.Geometries.Coordinate(); l.X = pt[0].X; l.Y = pt[0].Y; vertices.Add(l); //Collection<GeoAPI.Geometries.IGeometry> geom = new Collection<GeoAPI.Geometries.IGeometry>(); GeometryFactory gf = new NetTopologySuite.Geometries.GeometryFactory(); GeoAPI.Geometries.ILinearRing shell = gf.CreateLinearRing(vertices.ToArray()); GeoAPI.Geometries.IPolygon polygon = gf.CreatePolygon(shell, null); SharpMap.Data.Providers.GeometryProvider geomProvider= new SharpMap.Data.Providers.GeometryProvider(polygon); SharpMap.Layers.VectorLayer layerParcels = new SharpMap.Layers.VectorLayer("Parcels"); SharpMap.Styles.VectorStyle style = new SharpMap.Styles.VectorStyle(); style.Fill = new SolidBrush(Color.FromArgb(200,color)); style.Outline = new Pen(new SolidBrush(color)); layerParcels.Style = style; layerParcels.Style.EnableOutline = true; layerParcels.DataSource = geomProvider; layerParcels.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; mapBox1.ActiveTool = SharpMap.Forms.MapBox.Tools.Pan; var fdt = new SharpMap.Data.FeatureDataTable(); fdt.Columns.Add(new System.Data.DataColumn("id", typeof(uint))); fdt.Columns.Add(new System.Data.DataColumn("label", typeof(string))); var fdr = (SharpMap.Data.FeatureDataRow)fdt.NewRow(); fdr.ItemArray = new object[] { 1, labelname }; fdr.Geometry = polygon; fdt.AddRow(fdr); var dataprovider = new SharpMap.Data.Providers.GeometryFeatureProvider(fdt); var ll = new SharpMap.Layers.LabelLayer("llayer"); ll.DataSource = dataprovider; ll.LabelColumn = "label"; ll.Style.Font = new Font("Eurostile Extended", 16,FontStyle.Bold); mapBox1.Map.Layers.Add(layerParcels); mapBox1.Map.Layers.Add(ll); mapBox1.Map.ZoomToExtents(); mapBox1.Refresh(); }
public static System.Collections.Generic.List <OSM.API.v0_6.GeoPoint> GetUnionPolygon( System.Collections.Generic.IEnumerable <System.Collections.Generic.IEnumerable <OSM.API.v0_6.GeoPoint> > polygons) { NetTopologySuite.Geometries.GeometryFactory geomFactory = new NetTopologySuite.Geometries.GeometryFactory(); System.Collections.Generic.List <NetTopologySuite.Geometries.Geometry> lsPolygons = new System.Collections.Generic.List <NetTopologySuite.Geometries.Geometry>(); foreach (System.Collections.Generic.IEnumerable <OSM.API.v0_6.GeoPoint> coords in polygons) { NetTopologySuite.Geometries.Polygon poly = geomFactory.CreatePolygon(ToNetTopologyCoordinates(coords)); lsPolygons.Add(poly); } NetTopologySuite.Geometries.Geometry ig = NetTopologySuite.Operation.Union.CascadedPolygonUnion.Union(lsPolygons); System.Console.WriteLine(ig.GetType().FullName); if (ig is NetTopologySuite.Geometries.Polygon) { System.Console.WriteLine("mulip"); goto SIMPLIFY_POLYGON_AND_GET_UNION; } if (!(ig is NetTopologySuite.Geometries.MultiPolygon)) { System.Console.WriteLine("Error: Geometry is not a multipolygon!"); throw new System.InvalidOperationException("Geometry is not a multipolygon"); } NetTopologySuite.Geometries.MultiPolygon lalala = (NetTopologySuite.Geometries.MultiPolygon)ig; // var convaveHull = ConcaveHull.Init.foo(lalala.Coordinates); // convaveHull = ToCounterClockWise(convaveHull); // return convaveHull; // var cc = new NetTopologySuite.Hull.ConcaveHull(ig, 0); // var cc = new NetTopologySuite.Hull.ConcaveHull(ig, 0.00049); var cc = new NetTopologySuite.Hull.ConcaveHull(ig, 0.00001); ig = cc.GetConcaveHull; SIMPLIFY_POLYGON_AND_GET_UNION: ig = NetTopologySuite.Simplify.DouglasPeuckerSimplifier.Simplify(ig, 0.00001); NetTopologySuite.Geometries.Polygon unionPolygon = (NetTopologySuite.Geometries.Polygon)ig; System.Console.WriteLine(unionPolygon.Shell.Coordinates); System.Collections.Generic.List <OSM.API.v0_6.GeoPoint> lsUnionPolygonPoints = new System.Collections.Generic.List <OSM.API.v0_6.GeoPoint>(); for (int i = 0; i < unionPolygon.Shell.Coordinates.Length; ++i) { lsUnionPolygonPoints.Add(new OSM.API.v0_6.GeoPoint(unionPolygon.Shell.Coordinates[i].X, unionPolygon.Shell.Coordinates[i].Y)); } lsUnionPolygonPoints = ToCounterClockWise(lsUnionPolygonPoints); return(lsUnionPolygonPoints); }
private void LoadParcels(List <PointD> pt, Color color, string labelname) { SharpMap.Map map = new SharpMap.Map(); List <GeoAPI.Geometries.Coordinate> vertices = new List <GeoAPI.Geometries.Coordinate>(); foreach (PointD i in pt) { GeoAPI.Geometries.Coordinate p = new GeoAPI.Geometries.Coordinate(); p.X = i.X; p.Y = i.Y; vertices.Add(p); } GeoAPI.Geometries.Coordinate l = new GeoAPI.Geometries.Coordinate(); l.X = pt[0].X; l.Y = pt[0].Y; vertices.Add(l); //Collection<GeoAPI.Geometries.IGeometry> geom = new Collection<GeoAPI.Geometries.IGeometry>(); GeometryFactory gf = new NetTopologySuite.Geometries.GeometryFactory(); GeoAPI.Geometries.ILinearRing shell = gf.CreateLinearRing(vertices.ToArray()); GeoAPI.Geometries.IPolygon polygon = gf.CreatePolygon(shell, null); SharpMap.Data.Providers.GeometryProvider geomProvider = new SharpMap.Data.Providers.GeometryProvider(polygon); SharpMap.Layers.VectorLayer layerParcels = new SharpMap.Layers.VectorLayer("Parcels"); SharpMap.Styles.VectorStyle style = new SharpMap.Styles.VectorStyle(); style.Fill = new SolidBrush(Color.FromArgb(200, color)); style.Outline = new Pen(new SolidBrush(color)); layerParcels.Style = style; layerParcels.Style.EnableOutline = true; layerParcels.DataSource = geomProvider; layerParcels.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; mapBox1.ActiveTool = SharpMap.Forms.MapBox.Tools.Pan; var fdt = new SharpMap.Data.FeatureDataTable(); fdt.Columns.Add(new System.Data.DataColumn("id", typeof(uint))); fdt.Columns.Add(new System.Data.DataColumn("label", typeof(string))); var fdr = (SharpMap.Data.FeatureDataRow)fdt.NewRow(); fdr.ItemArray = new object[] { 1, labelname }; fdr.Geometry = polygon; fdt.AddRow(fdr); var dataprovider = new SharpMap.Data.Providers.GeometryFeatureProvider(fdt); var ll = new SharpMap.Layers.LabelLayer("llayer"); ll.DataSource = dataprovider; ll.LabelColumn = "label"; ll.Style.Font = new Font("Eurostile Extended", 16, FontStyle.Bold); mapBox1.Map.Layers.Add(layerParcels); mapBox1.Map.Layers.Add(ll); mapBox1.Map.ZoomToExtents(); mapBox1.Refresh(); }
public static IGeometry ToPolygon(QuadEdge[] e) { var ringPts = new[] { e[0].Orig.Coordinate, e[1].Orig.Coordinate, e[2].Orig.Coordinate, e[0].Orig.Coordinate }; var fact = new GeometryFactory(); ILinearRing ring = fact.CreateLinearRing(ringPts); IPolygon tri = fact.CreatePolygon(ring, null); return tri; }
public static IGeometry ToPolygon(Vertex[] v) { var ringPts = new[] { v[0].Coordinate, v[1].Coordinate, v[2].Coordinate, v[0].Coordinate }; var fact = new GeometryFactory(); var ring = fact.CreateLinearRing(ringPts); var tri = fact.CreatePolygon(ring, null); return tri; }
public IGeometry GetGeometry(GeometryFactory fact) { ILinearRing ring = fact.CreateLinearRing(GetCoordinates()); IPolygon tri = fact.CreatePolygon(ring, null); return tri; }
/// <summary> /// /// Add a list of vector layers to the map. /// </summary> /// <param name="vectorLayers"></param> public void AddVectorLayers(List<FeatureInfo> vectorLayers) { int counter = 0; if (vectorLayers == null) return; vectorLayers.ForEach(layer => { VectorLayer vectorLayer = new VectorLayer("VectorLayer-" + counter); GeometryFactory factory = new GeometryFactory(); List<IGeometry> geometries = new List<IGeometry>(); FeatureDataTable featureData = new FeatureDataTable(); featureData.Columns.Add("text", typeof(String)); featureData.Columns.Add("style", typeof(MapExport.Style)); layer.features.ForEach(feature => { FeatureDataRow dataRow = featureData.NewRow(); dataRow["text"] = feature.attributes.text; dataRow["style"] = feature.attributes.style; List<GeoAPI.Geometries.Coordinate> vertices = new List<GeoAPI.Geometries.Coordinate>(); feature.coordinates.ForEach(coordinate => { double x = coordinate[0]; double y = coordinate[1]; vertices.Add((new GeoAPI.Geometries.Coordinate(x, y))); }); switch (feature.type) { case "Text": case "Point": if (vertices.Count > 0) { var point = factory.CreatePoint(new GeoAPI.Geometries.Coordinate(vertices[0])); dataRow.Geometry = point; } break; case "LineString": var lineString = factory.CreateLineString(vertices.ToArray()); dataRow.Geometry = lineString; break; case "Polygon": var polygon = factory.CreatePolygon(vertices.ToArray()); dataRow.Geometry = polygon; break; } featureData.AddRow(dataRow); }); vectorLayer.DataSource = new SharpMap.Data.Providers.GeometryFeatureProvider(featureData); //vectorLayer.DataSource = new SharpMap.Data.Providers.FeatureProvider(featureData); //vectorLayer.Theme = new CustomTheme(GetFeatureStyle); vectorLayer.Theme = new CustomTheme(GetFeatureStyle); map.Layers.Add(vectorLayer); LabelLayer labels = new LabelLayer("Labels"); labels.DataSource = vectorLayer.DataSource; labels.Enabled = true; labels.LabelColumn = "text"; labels.Theme = new CustomTheme(GetLabelStyle); labels.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; labels.SmoothingMode = SmoothingMode.HighQuality; labels.SRID = vectorLayer.SRID; map.Layers.Add(labels); counter++; }); }