internal Polygon(NTSPolygon polygon) { Shell = NTSConverter.FromLinearRing(polygon.Shell); Holes = polygon.Holes.Select(NTSConverter.FromLinearRing).ToArray(); _ntsPolygon = new Lazy <NTSPolygon>(() => polygon); }
} // End Function CalculateArea public static double CalculateArea2(Wgs84Coordinates[] mycoordinates) { double[] pointsArray = mycoordinates.ToDoubleArray(); var z = new double[mycoordinates.Length]; // public static double[] ToDoubleArray(this Wgs84Coordinates[] mycoordinates) // source projection is WGS1984 var projFrom = DotSpatial.Projections.KnownCoordinateSystems.Geographic.World.WGS1984; // most complicated problem - you have to find most suitable projection var projTo = DotSpatial.Projections.KnownCoordinateSystems.Projected.UtmWgs1984.WGS1984UTMZone37N; projTo = DotSpatial.Projections.KnownCoordinateSystems.Projected.Europe.EuropeAlbersEqualAreaConic; projTo = DotSpatial.Projections.KnownCoordinateSystems.Projected.WorldSpheroid.CylindricalEqualAreasphere; projTo = DotSpatial.Projections.KnownCoordinateSystems.Projected.World.CylindricalEqualAreaworld; DotSpatial.Projections.Reproject.ReprojectPoints(pointsArray, z, projFrom, projTo, 0, pointsArray.Length / 2); // assemblying new points array to create polygon var points = new System.Collections.Generic.List <GeoAPI.Geometries.Coordinate>(pointsArray.Length / 2); for (int i = 0; i < pointsArray.Length / 2; i++) { points.Add(new GeoAPI.Geometries.Coordinate(pointsArray[i * 2], pointsArray[i * 2 + 1])); } NetTopologySuite.Geometries.LinearRing lr = new NetTopologySuite.Geometries.LinearRing(points.ToArray()); GeoAPI.Geometries.IPolygon poly = new NetTopologySuite.Geometries.Polygon(lr); return(poly.Area); }
/// <summary> /// Returns the centroid of a building. /// </summary> private static LatLon GetCentroid(CompleteWay building) { var points = building.Nodes.Select( x => new GeoAPI.Geometries.Coordinate(x.Latitude.Value, x.Longitude.Value)) .ToArray(); var poly = new NetTopologySuite.Geometries.Polygon(new NetTopologySuite.Geometries.LinearRing(points)); var centroid = poly.Centroid.Coordinate; return(new LatLon(centroid.X, centroid.Y)); }
public static Task <List <string> > GenerateCoveringGeohashes(this Geohasher hasher, GeoJsonPolygon <GeoJson2DGeographicCoordinates> polygon, int precision = 4) { var outerRing = new NetTopologySuite.Geometries.LinearRing( (from coord in polygon.Coordinates.Exterior.Positions select new NetTopologySuite.Geometries.Coordinate(coord.Latitude, coord.Longitude)).ToArray() ); var p = new NetTopologySuite.Geometries.Polygon(outerRing); return(hasher.GetHashesAsync(p, precision, Mode.Intersect)); }
private static IMultiPolygon ReadMultiPolygon(JsonTextReader jreader) { if (jreader == null) { throw new ArgumentNullException("reader", "A valid JSON reader object is required."); } IMultiPolygon areas = null; if (jreader.TokenClass == JsonTokenClass.Array) { jreader.ReadToken(JsonTokenClass.Array); List <IPolygon> polygons = new List <IPolygon>(); while (jreader.TokenClass == JsonTokenClass.Array) { jreader.ReadToken(JsonTokenClass.Array); //Read the outer shell ILinearRing shell = null; if (jreader.TokenClass == JsonTokenClass.Array) { Coordinate[] coordinates = new Coordinate[] { }; Read(ref coordinates, jreader); shell = new NetTopologySuite.Geometries.LinearRing(coordinates); } //Read all the holes List <ILinearRing> list = new List <ILinearRing>(); while (jreader.TokenClass == JsonTokenClass.Array) { Coordinate[] coordinates = new Coordinate[] { }; Read(ref coordinates, jreader); ILinearRing hole = new NetTopologySuite.Geometries.LinearRing(coordinates); list.Add(hole); } jreader.ReadToken(JsonTokenClass.EndArray); //An outer shell was found so a polygon can be created if (shell != null) { IPolygon area = new NetTopologySuite.Geometries.Polygon(shell, list.ToArray()); polygons.Add(area); } } jreader.ReadToken(JsonTokenClass.EndArray); areas = new NetTopologySuite.Geometries.MultiPolygon(polygons.ToArray()); } return(areas); }
public Polygon(NetTopologySuite.Geometries.Polygon polygon) : base(SpatialShapeType.Polygon) { if (polygon == null) { throw new ArgumentNullException(nameof(polygon)); } Vertices ??= new List <Coordinates>(); foreach (Coordinate coordinate in polygon.Coordinates) { Vertices.Add(new Coordinates(coordinate.Y, coordinate.X)); } }
public static void CustomizeGeometryMultiPolygon(this IFixture fixture) { fixture.Customize <NetTopologySuite.Geometries.MultiPolygon>(customization => customization.FromFactory(generator => { var polygonCount = generator.Next(1, 4); var polygons = new NetTopologySuite.Geometries.Polygon[polygonCount]; for (var polygonIndex = 0; polygonIndex < polygonCount; polygonIndex++) { var offsetX = 10.0 * polygonIndex; var offsetY = 10.0 * polygonIndex; var shell = new NetTopologySuite.Geometries.LinearRing( new [] { new NetTopologySuite.Geometries.Point(offsetX, offsetY).Coordinate, new NetTopologySuite.Geometries.Point(offsetX, offsetY + 5.0).Coordinate, new NetTopologySuite.Geometries.Point(offsetX + 5.0, offsetY + 5.0).Coordinate, new NetTopologySuite.Geometries.Point(offsetX + 5.0, offsetY).Coordinate, new NetTopologySuite.Geometries.Point(offsetX, offsetY).Coordinate }); var holes = new[] // points are enumerated counter clock wise { new NetTopologySuite.Geometries.LinearRing( new[] { new NetTopologySuite.Geometries.Point(offsetX + 1.0, offsetY + 2.0).Coordinate, new NetTopologySuite.Geometries.Point(offsetX + 2.0, offsetY + 2.0).Coordinate, new NetTopologySuite.Geometries.Point(offsetX + 2.0, offsetY + 3.0).Coordinate, new NetTopologySuite.Geometries.Point(offsetX + 1.0, offsetY + 3.0).Coordinate, new NetTopologySuite.Geometries.Point(offsetX + 1.0, offsetY + 2.0).Coordinate }), new NetTopologySuite.Geometries.LinearRing( new[] { new NetTopologySuite.Geometries.Point(offsetX + 3.0, offsetY + 1.0).Coordinate, new NetTopologySuite.Geometries.Point(offsetX + 4.0, offsetY + 1.0).Coordinate, new NetTopologySuite.Geometries.Point(offsetX + 4.0, offsetY + 2.0).Coordinate, new NetTopologySuite.Geometries.Point(offsetX + 3.0, offsetY + 2.0).Coordinate, new NetTopologySuite.Geometries.Point(offsetX + 3.0, offsetY + 1.0).Coordinate }) }; polygons[polygonIndex] = new NetTopologySuite.Geometries.Polygon(shell, holes, GeometryConfiguration.GeometryFactory); } return(new NetTopologySuite.Geometries.MultiPolygon(polygons)); }).OmitAutoProperties() ); }
/// <summary> /// Remove all holes in a multipolygon /// </summary> /// <param name="multiPolygon"></param> /// <returns></returns> public static IGeometry RemoveHoles(this MultiPolygon multiPolygon) { IGeometry newGeometry = null; for (var i = 0; i < multiPolygon.NumGeometries; i++) { var polygon = new Polygon((ILinearRing)((IPolygon)multiPolygon.GetGeometryN(i)).ExteriorRing); newGeometry = i == 0 ? polygon : newGeometry.Union(polygon); } return(newGeometry); }
public static GeometryObject SplitWorldExtent(Polygon poly) { MultiPolygon newpoly = new MultiPolygon(); List <LineString> OuterlineStrings = new List <LineString>(); List <LineString> InnerlineStrings = new List <LineString>(); OuterlineStrings.AddRange(SplitWorldExtent(poly.LineStrings.First())); foreach (LineString lineString in poly.LineStrings.Skip(1)) { InnerlineStrings.AddRange(SplitWorldExtent(lineString)); } if (OuterlineStrings.Count == 1) { return(poly); } List <Polygon> newpolygons = new List <Polygon>(); if (OuterlineStrings.Count > 0) { foreach (LineString ls in OuterlineStrings) { Polygon curpoly = new Polygon(); newpoly.Polygons.Add(curpoly); curpoly.LineStrings.Add(ls); foreach (var innerls in InnerlineStrings) { NetTopologySuite.IO.WKTReader wktreader = new NetTopologySuite.IO.WKTReader(); var innerlr = wktreader.Read(innerls.ToWkt()); NetTopologySuite.Geometries.Polygon polygon = (NetTopologySuite.Geometries.Polygon)wktreader.Read(curpoly.ToWkt()); if (polygon.Contains(innerlr)) { curpoly.LineStrings.Add(innerls); } } newpolygons.Add(curpoly); } } return(newpoly); }
public static Polygon FromGeometryPolygon(NetTopologySuite.Geometries.Polygon polygon) { if (polygon == null) { throw new ArgumentNullException(nameof(polygon)); } var boundingBox = new BoundingBox2D( polygon.EnvelopeInternal.MinX, polygon.EnvelopeInternal.MinY, polygon.EnvelopeInternal.MaxX, polygon.EnvelopeInternal.MaxY ); var lineStrings = new List <NetTopologySuite.Geometries.LineString> { polygon.ExteriorRing }; lineStrings.AddRange(polygon.InteriorRings); var offset = 0; var parts = new int[lineStrings.Count]; for (var index = 0; index < lineStrings.Count; index++) { parts[index] = offset; var line = lineStrings[index]; offset += line.NumPoints; } var points = lineStrings .SelectMany(line => line.Coordinates) .Select(coordinate => new Point(coordinate.X, coordinate.Y)) .ToArray(); return(new Polygon(boundingBox, parts, points)); }
private XmlDocument InsertInspektionsroutenNames(XmlDocument xml, XmlNamespaceManager nsmgr, EmsgGisReportParameter reportparams) { if (reportparams == null) { return(this.InsertInspektionsroutenNames(xml, nsmgr)); } string[] bboxCoordinates = reportparams.BoundingBox.Split(','); Coordinate bottomLeft = new Coordinate(float.Parse(bboxCoordinates[0], CultureInfo.InvariantCulture.NumberFormat), float.Parse(bboxCoordinates[1], CultureInfo.InvariantCulture.NumberFormat)); Coordinate topRight = new Coordinate(float.Parse(bboxCoordinates[2], CultureInfo.InvariantCulture.NumberFormat), float.Parse(bboxCoordinates[3], CultureInfo.InvariantCulture.NumberFormat)); Coordinate bottomRight = new Coordinate(float.Parse(bboxCoordinates[2], CultureInfo.InvariantCulture.NumberFormat), float.Parse(bboxCoordinates[1], CultureInfo.InvariantCulture.NumberFormat)); Coordinate topLeft = new Coordinate(float.Parse(bboxCoordinates[0], CultureInfo.InvariantCulture.NumberFormat), float.Parse(bboxCoordinates[3], CultureInfo.InvariantCulture.NumberFormat)); ILinearRing linearRing = new NetTopologySuite.Geometries.LinearRing(new Coordinate[] { topLeft, topRight, bottomRight, bottomLeft, topLeft }); IGeometry filterGeom = new NetTopologySuite.Geometries.Polygon(linearRing); filterGeom.SRID = GisConstants.SRID; var inspekrouten = inspektionsRouteGISService.GetInspektionsrouteByFilterGeom(filterGeom); return(this.InsertInspektionsroutenNames(xml, nsmgr, inspekrouten)); }
public static void Test() { string s1 = "POLYGON((7.5999034 47.5506347,7.5997595 47.5507183,7.5998959 47.5508256,7.5999759 47.5508885,7.6001195 47.550805,7.5999034 47.5506347))"; string s2 = "POLYGON((7.6003356 47.5509754,7.6001195 47.550805,7.5999759 47.5508885,7.6000322 47.5509328,7.6001926 47.551059,7.6003356 47.5509754))"; s1 = "POLYGON((7.5999034 47.5506347,7.6001195 47.550805,7.5999759 47.5508885,7.5998959 47.5508256,7.5997595 47.5507183,7.5999034 47.5506347))"; s2 = "POLYGON((7.6003356 47.5509754,7.6001926 47.551059,7.6000322 47.5509328,7.5999759 47.5508885,7.6001195 47.550805,7.6003356 47.5509754))"; // NetTopologySuite.Geometries.Implementation.CoordinateArraySequenceFactory // GeoAPI.Geometries.IGeometryFactory geoFactory = new NetTopologySuite.Geometries.GeometryFactory(); NetTopologySuite.IO.WKTReader wr = new NetTopologySuite.IO.WKTReader(); Wgs84Coordinates[] coords1 = PolygonParsingExtensions.PolygonStringToCoordinates(s1); Wgs84Coordinates[] coords2 = PolygonParsingExtensions.PolygonStringToCoordinates(s2); var lr = new NetTopologySuite.Geometries.LinearRing(coords1.ToNetTopologyCoordinates()); System.Console.WriteLine(lr.IsValid); var x = new NetTopologySuite.Geometries.Polygon(new NetTopologySuite.Geometries.LinearRing(coords1.ToNetTopologyCoordinates())); System.Console.WriteLine(x.IsValid); NetTopologySuite.Geometries.GeometryFactory geomFactory = new NetTopologySuite.Geometries.GeometryFactory(); GeoAPI.Geometries.IPolygon poly1 = geomFactory.CreatePolygon(coords1.ToNetTopologyCoordinates()); GeoAPI.Geometries.IPolygon poly2 = geomFactory.CreatePolygon(coords2.ToNetTopologyCoordinates()); /* * GeoAPI.Geometries.IPolygon poly1 = (GeoAPI.Geometries.IPolygon)wr.Read(s1); * GeoAPI.Geometries.IPolygon poly2 = (GeoAPI.Geometries.IPolygon)wr.Read(s2); */ poly1.SRID = 4326; poly2.SRID = 4326; CalculateArea2(coords1); CalculateArea2(coords2); System.Console.WriteLine(poly1.Area); System.Console.WriteLine(poly2.Area); GeoAPI.Geometries.IPolygon poly3quick = (GeoAPI.Geometries.IPolygon)poly1.Union(poly2); System.Console.WriteLine(poly3quick.IsValid); // https://gis.stackexchange.com/questions/209797/how-to-get-geometry-points-using-geo-api System.Console.Write(poly1.IsValid); System.Console.Write(poly2.IsValid); System.Collections.Generic.List <GeoAPI.Geometries.IGeometry> lsPolygons = new System.Collections.Generic.List <GeoAPI.Geometries.IGeometry>(); lsPolygons.Add(poly1); lsPolygons.Add(poly2); GeoAPI.Geometries.IGeometry ig = NetTopologySuite.Operation.Union.CascadedPolygonUnion.Union(lsPolygons); System.Console.WriteLine(ig.GetType().FullName); GeoAPI.Geometries.IPolygon poly3 = (GeoAPI.Geometries.IPolygon)ig; System.Console.WriteLine(poly3); // POLYGON ((7.5997595 47.5507183, 7.5999034 47.5506347, 7.6001195 47.550805, 7.6003356 47.5509754 // , 7.6001926 47.551059, 7.6000322 47.5509328, 7.5999759 47.5508885 // , 7.5998959 47.5508256, 7.5997595 47.5507183)) System.Console.WriteLine(poly3.Shell.Coordinates); /* * // GeoAPI.Geometries.IPolygon poly3 = (GeoAPI.Geometries.IPolygon)ig; * NetTopologySuite.Geometries.MultiPolygon poly3a = (NetTopologySuite.Geometries.MultiPolygon)ig; * GeoAPI.Geometries.IGeometry ig2 = poly3a.ConvexHull(); * System.Console.WriteLine(ig2.GetType().FullName); */ // GeoAPI.Geometries.IPolygon poly4 = (GeoAPI.Geometries.IPolygon)ig2; // System.Console.WriteLine(poly4); System.Console.WriteLine("--- Press any key to continue --- "); System.Console.ReadKey(); } // End Sub Test
} // End Function PolygonArea public static double CalculateArea(Wgs84Coordinates[] mycoordinates) { double[] latLonPoints = new double[mycoordinates.Length * 2]; double[] z = new double[mycoordinates.Length]; // dotspatial takes the x,y in a single array, and z in a separate array. I'm sure there's a // reason for this, but I don't know what it is. for (int i = 0; i < mycoordinates.Length; i++) { latLonPoints[i * 2] = (double)mycoordinates[i].Longitude; latLonPoints[i * 2 + 1] = (double)mycoordinates[i].Latitude; z[i] = 0; } // Next i // source projection is WGS1984 // https://productforums.google.com/forum/#!msg/gec-data-discussions/FxwUP7bd59g/02tvMDD3vtEJ // https://epsg.io/3857 DotSpatial.Projections.ProjectionInfo projFrom = DotSpatial.Projections.KnownCoordinateSystems.Geographic.World.WGS1984; // most complicated problem - you have to find most suitable projection DotSpatial.Projections.ProjectionInfo projTo = DotSpatial.Projections.KnownCoordinateSystems.Projected.UtmWgs1984.WGS1984UTMZone37N; projTo = DotSpatial.Projections.KnownCoordinateSystems.Projected.Europe.EuropeAlbersEqualAreaConic; // 6350.9772005155683 // projTo= DotSpatial.Projections.KnownCoordinateSystems.Geographic.World.WGS1984; // 5.215560750019806E-07 // projTo = DotSpatial.Projections.KnownCoordinateSystems.Projected.WorldSpheroid.EckertIVsphere; // 6377.26664171461 // projTo = DotSpatial.Projections.KnownCoordinateSystems.Projected.World.EckertIVworld; // 6391.5626849671826 projTo = DotSpatial.Projections.KnownCoordinateSystems.Projected.World.CylindricalEqualAreaworld; // 6350.6506013739854 /* * projTo = DotSpatial.Projections.KnownCoordinateSystems.Projected.WorldSpheroid.CylindricalEqualAreasphere; // 6377.2695087222382 * projTo = DotSpatial.Projections.KnownCoordinateSystems.Projected.WorldSpheroid.EquidistantCylindricalsphere; // 6448.6818862780929 * projTo = DotSpatial.Projections.KnownCoordinateSystems.Projected.World.Polyconicworld; // 8483.7701716953889 * projTo = DotSpatial.Projections.KnownCoordinateSystems.Projected.World.EquidistantCylindricalworld; // 6463.1380225215107 * projTo = DotSpatial.Projections.KnownCoordinateSystems.Projected.World.EquidistantConicworld; // 8197.4427198320627 * projTo = DotSpatial.Projections.KnownCoordinateSystems.Projected.World.VanderGrintenIworld; // 6537.3942984174937 * projTo = DotSpatial.Projections.KnownCoordinateSystems.Projected.World.WebMercator; // 6535.5119516421109 * projTo = DotSpatial.Projections.KnownCoordinateSystems.Projected.World.Mercatorworld; // 6492.7180733950809 * projTo = DotSpatial.Projections.KnownCoordinateSystems.Projected.SpheroidBased.Lambert2; // 9422.0631835013628 * projTo = DotSpatial.Projections.KnownCoordinateSystems.Projected.SpheroidBased.Lambert2Wide; // 9422.0614012926817 * projTo = DotSpatial.Projections.KnownCoordinateSystems.Projected.TransverseMercator.WGS1984lo33; // 6760.01638841012 * projTo = DotSpatial.Projections.KnownCoordinateSystems.Projected.Europe.EuropeAlbersEqualAreaConic; // 6350.9772005155683 * projTo = DotSpatial.Projections.KnownCoordinateSystems.Projected.UtmOther.EuropeanDatum1950UTMZone37N; // 6480.7883094931021 */ // ST_Area(g, false) 6379.25032051953 // ST_Area(g, true) 6350.65051177517 // ST_Area(g) 5.21556075001092E-07 // prepare for ReprojectPoints (it's mutate array) DotSpatial.Projections.Reproject.ReprojectPoints( latLonPoints, z, projFrom, projTo , 0, latLonPoints.Length / 2 ); // assemblying new points array to create polygon GeoAPI.Geometries.Coordinate[] polyPoints = new GeoAPI.Geometries.Coordinate[latLonPoints.Length / 2]; for (int i = 0; i < latLonPoints.Length / 2; ++i) { polyPoints[i] = new GeoAPI.Geometries.Coordinate(latLonPoints[i * 2], latLonPoints[i * 2 + 1]); } // Next i // Assembling linear ring to create polygon NetTopologySuite.Geometries.LinearRing lr = new NetTopologySuite.Geometries.LinearRing(polyPoints); if (!lr.IsValid) { throw new System.IO.InvalidDataException("Coordinates are invalid."); } GeoAPI.Geometries.IPolygon poly = new NetTopologySuite.Geometries.Polygon(lr); if (!poly.IsValid) { throw new System.IO.InvalidDataException("Polygon is invalid."); } return(poly.Area); } // End Function CalculateArea
public static void CustomizeMultiPolygon(this IFixture fixture) { fixture.Customize <Polygon>(customization => customization.FromFactory(generator => { var polygonCount = generator.Next(1, 4); var polygons = new NetTopologySuite.Geometries.Polygon[polygonCount]; for (var polygonIndex = 0; polygonIndex < polygonCount; polygonIndex++) { var offsetX = 10.0 * polygonIndex; var offsetY = 10.0 * polygonIndex; var shell = new NetTopologySuite.Geometries.LinearRing( new [] { new NetTopologySuite.Geometries.Point(offsetX, offsetY).Coordinate, new NetTopologySuite.Geometries.Point(offsetX, offsetY + 5.0).Coordinate, new NetTopologySuite.Geometries.Point(offsetX + 5.0, offsetY + 5.0).Coordinate, new NetTopologySuite.Geometries.Point(offsetX + 5.0, offsetY).Coordinate, new NetTopologySuite.Geometries.Point(offsetX, offsetY).Coordinate }); var holes = new[] // points are enumerated counter clock wise { new NetTopologySuite.Geometries.LinearRing( new[] { new NetTopologySuite.Geometries.Point(offsetX + 1.0, offsetY + 2.0).Coordinate, new NetTopologySuite.Geometries.Point(offsetX + 2.0, offsetY + 2.0).Coordinate, new NetTopologySuite.Geometries.Point(offsetX + 2.0, offsetY + 3.0).Coordinate, new NetTopologySuite.Geometries.Point(offsetX + 1.0, offsetY + 3.0).Coordinate, new NetTopologySuite.Geometries.Point(offsetX + 1.0, offsetY + 2.0).Coordinate }), new NetTopologySuite.Geometries.LinearRing( new[] { new NetTopologySuite.Geometries.Point(offsetX + 3.0, offsetY + 1.0).Coordinate, new NetTopologySuite.Geometries.Point(offsetX + 4.0, offsetY + 1.0).Coordinate, new NetTopologySuite.Geometries.Point(offsetX + 4.0, offsetY + 2.0).Coordinate, new NetTopologySuite.Geometries.Point(offsetX + 3.0, offsetY + 2.0).Coordinate, new NetTopologySuite.Geometries.Point(offsetX + 3.0, offsetY + 1.0).Coordinate }) }; polygons[polygonIndex] = new NetTopologySuite.Geometries.Polygon(shell, holes); } var linearRings = polygons .SelectMany(polygon => new[] { polygon.Shell }.Concat(polygon.Holes)) .ToArray(); var parts = new int[linearRings.Length]; var points = new Point[polygons.Sum(polygon => polygon.Shell.NumPoints + polygon.Holes.Sum(hole => hole.NumPoints))]; var offset = 0; for (var ringIndex = 0; ringIndex < linearRings.Length; ringIndex++) { var linearRing = linearRings[ringIndex]; parts[ringIndex] = offset; for (var pointIndex = 0; pointIndex < linearRing.NumPoints; pointIndex++) { var point = linearRing.GetPointN(pointIndex); points[offset + pointIndex] = new Point(point.X, point.Y); } offset += linearRing.NumPoints; } var boundingBox = new BoundingBox2D( points.Min(p => p.X), points.Min(p => p.Y), points.Max(p => p.X), points.Max(p => p.Y) ); return(new Polygon(boundingBox, parts, points)); }).OmitAutoProperties() ); }
private void DealerSearch(System.Windows.Point point) { Cursor = Cursors.Wait; mapControl.SetMapLocation(point, 12, srid); reachableObjectLayer.Shapes.Clear(); isochroneLayer.Shapes.Clear(); var waypoint = new WaypointDesc() { linkType = LinkType.NEXT_SEGMENT, wrappedCoords = new XRoute.Point[] { new XRoute.Point() { point = new PlainPoint() { x = point.X, y = point.Y, }, }, }, }; var expansionDesc = new ExpansionDescription() { expansionType = ExpansionType.EXP_TIME, wrappedHorizons = new int[] { 900 }, }; var options = new ReachableObjectsOptions() { expansionDesc = expansionDesc, linkType = LinkType.NEXT_SEGMENT, routingDirection = RoutingDirectionType.FORWARD, geodatasourceLayer = XDealerSample.Properties.Settings.Default.GeoDataSource, }; var cc = new CallerContext() { wrappedProperties = new CallerContextProperty[] { new CallerContextProperty() { key = "CoordFormat", value = "PTV_MERCATOR" }, new CallerContextProperty() { key = "Profile", value = "carfast" }, } }; var isoOptions = new IsochroneOptions() { expansionDesc = expansionDesc, isoDetail = IsochroneDetail.POLYS_ONLY, polygonCalculationMode = PolygonCalculationMode.NODE_BASED, }; ReachableObjects foundObjects = null; Isochrone isochrone = null; using (var xRouteClient = new XRouteWSClient()) { try { foundObjects = xRouteClient.searchForReachableObjects(waypoint, null, null, options, null, cc); } catch (Exception exception) { MessageBox.Show( "Exception while searching for objects.\n\nException type: " + exception.GetType().ToString() + "\nMessage: " + exception.Message); Cursor = null; return; } try { isochrone = xRouteClient.calculateIsochrones(waypoint, null, isoOptions, cc); } catch (Exception exception) { MessageBox.Show( "Exception while calculating isochrone.\n\nException type: " + exception.GetType().ToString() + "\nMessage: " + exception.Message); Cursor = null; return; } } foreach (var foundObject in foundObjects.wrappedReachableObject) { var ball = new Ball() { Height = 10, Width = 10, Tag = [email protected], ToolTip = "", Color = Colors.Blue, }; ball.ToolTipOpening += ball_ToolTipOpening; var winPoint = new System.Windows.Point() { X = [email protected], Y = [email protected], }; ShapeCanvas.SetLocation(ball, winPoint); reachableObjectLayer.Shapes.Add(ball); } var linearRing = new NetTopologySuite.Geometries.LinearRing( isochrone.wrappedIsochrones[0].polys.lineString.wrappedPoints .Select(p => new GeoAPI.Geometries.Coordinate(p.x, p.y)) .ToArray() ); linearRing.Normalize(); var geom = new NetTopologySuite.Geometries.Polygon(linearRing); var bufferedGeom = geom.Buffer(100); var polygon = new MapPolygon() { Points = new PointCollection(bufferedGeom.Boundary.Coordinates.Select(c => new System.Windows.Point(c.X, c.Y))), Fill = new SolidColorBrush(Colors.AliceBlue), Opacity = 0.75, Stroke = new SolidColorBrush(Colors.DarkSlateGray) }; isochroneLayer.Shapes.Add(polygon); Cursor = null; }
public DrawingPolygon(NetTopologySuite.Geometries.Polygon polygon) { Update(polygon.Shell.Coordinates.Select(c => c.ToPoint()), polygon.Holes.Select(lr => lr.Coordinates.Select(c => c.ToPoint()))); }