/// <summary> /// A MultiPoint is simple if it has no repeated points. /// </summary> public virtual bool IsSimple(MultiPoint mp) { if (mp.IsEmpty) return true; var points = new HashSet<Coordinate>(); for (int i = 0; i < mp.NumGeometries; i++) { Point pt = (Point)mp.GetGeometryN(i); Coordinate p = pt.Coordinate; if (points.Contains(p)) return false; points.Add(p); } return true; }
protected Geometry CreateGeometry(GeometryType geometryType, Dimension dimension) { Geometry geometry = null; switch (geometryType) { case GeometryType.Point: geometry = new Point(); break; case GeometryType.LineString: geometry = new LineString(); break; case GeometryType.Polygon: geometry = new Polygon(); break; case GeometryType.MultiPoint: geometry = new MultiPoint(); break; case GeometryType.MultiLineString: geometry = new MultiLineString(); break; case GeometryType.MultiPolygon: geometry = new MultiPolygon(); break; case GeometryType.GeometryCollection: geometry = new GeometryCollection(); break; } geometry.Dimension = dimension; return geometry; }
public void MultiPs() { var c = new Coordinate[36]; var rnd = new Random(); var ccheck = new GeoAPI.Geometries.Coordinate[36]; var gf = new NetTopologySuite.Geometries.GeometryFactory(); for (var i = 0; i < 36; i++) { c[i] = new Coordinate((rnd.NextDouble() + 360) - 180, (rnd.NextDouble() * 180) - 90); var x = c[i].X; var y = c[i].Y; var ctemp = new GeoAPI.Geometries.Coordinate(x, y); ccheck[i] = ctemp; } GeoAPI.Geometries.IMultiPoint mpsCheck = gf.CreateMultiPoint(ccheck); var mps = new MultiPoint(c); for (var ii = 0; ii < mps.Coordinates.Count; ii++) { Assert.AreEqual(mps.Coordinates[ii].X, mpsCheck.Coordinates[ii].X); Assert.AreEqual(mps.Coordinates[ii].Y, mpsCheck.Coordinates[ii].Y); } }
/// <summary> /// Serializes an instance of MapAround.Geometry.MultiPoint into stream. /// </summary> /// <param name="stream">A stream to write serializing geometry</param> /// <param name="multiPoint">A multipoint geometry</param> public static void SerializeMultiPoint(Stream stream, MultiPoint multiPoint) { writeInt(stream, multiPoint.Points.Count); foreach (ICoordinate p in multiPoint.Points) { writeDouble(stream, p.X); writeDouble(stream, p.Y); } }
int INpgsqlTypeHandler <MultiPoint> .ValidateAndGetLength(MultiPoint value, ref NpgsqlLengthCache?lengthCache, NpgsqlParameter?parameter) => ValidateAndGetLength(value, ref lengthCache, parameter);
private void getPointPolylineOverlay(MultiPoint mp, Polyline polyline, OverlayType operation, GeometryCollection result, bool performSnapping, bool inverseArgs) { try { _geometry1 = mp; _geometry2 = polyline; bool isValid = true; try { init(performSnapping); PlanarGraph graph = PlanarGraph.Build(_geometry1, _geometry2); // classify edges and nodes foreach (PlanarGraphEdge edge in graph.Edges) { edge.IsVisited = false; switch (operation) { case OverlayType.Intersection: edge.Enabled = false; break; case OverlayType.Union: edge.Enabled = edge.Label.UsedByObject2; break; case OverlayType.Difference: edge.Enabled = inverseArgs ? edge.Label.UsedByObject2 : false; break; case OverlayType.SymmetricDifference: edge.Enabled = edge.Label.UsedByObject2; break; } } foreach (PlanarGraphNode node in graph.Nodes) { bool hasEnabledEdges = false; foreach (PlanarGraphEdge edge in node.IncidentEdges) if (edge.Enabled) { hasEnabledEdges = true; break; } if (hasEnabledEdges) node.Enabled = false; else { switch (operation) { case OverlayType.Intersection: node.Enabled = node.Label.UsedByObject1 && node.Label.UsedByObject2; break; case OverlayType.Union: node.Enabled = node.Label.UsedByObject1; break; case OverlayType.Difference: node.Enabled = inverseArgs ? false : !node.Label.UsedByObject2; break; case OverlayType.SymmetricDifference: node.Enabled = true; break; } } } // build results: // point List<PointD> points = graph.BuildPoints(); foreach (PointD p in points) result.Add(p); // polyline Polyline pl = graph.BuildPolyline(false, false); if (pl.CoordinateCount > 0) result.Add(pl); for (int i = 0; i < result.Count; i++) { IGeometry g = translateGeometry(result[i], _translationCenter.X, _translationCenter.Y); if (g is PointD) result[i] = g; } } catch (TopologyException) { if (!performSnapping) isValid = false; else throw new InvalidOperationException("Unable to complete operation correctly with this value of tolerance (PlanimertyAlgorithms.Tolerance)"); } if (isValid) return; else { // overlay has not been calculated. // it may be possible to calculate the overlay aligned to the grid getPointPolylineOverlay(mp, polyline, operation, result, true, inverseArgs); return; } } finally { _geometry1 = null; _geometry2 = null; } }
public static void Write(MultiPoint points, TextWriter writer) { if (points == null) return; if (writer == null) throw new ArgumentNullException("writer", "A valid text writer object is required"); JsonTextWriter jwriter = CreateWriter(writer); Write(points, jwriter); }
/// <summary> /// Converts a MultiPoint to <MultiPoint Tagged Text> /// format, then Appends it to the writer. /// </summary> /// <param name="multipoint">The MultiPoint to process.</param> /// <param name="level"></param> /// <param name="writer">The output writer to Append to.</param> protected void AppendMultiPointTaggedText(MultiPoint multipoint, int level, StringWriter writer) { writer.Write("MULTIPOINT "); AppendMultiPointText(multipoint, level, writer); }
public void Clone_an_invalid_multipoint_should_be_invalid() { var multiPoint = new MultiPoint(); multiPoint.Clone().IsValid.Should().BeFalse(); }
/// <summary> /// /// </summary> /// <param name="multiPoint"></param> /// <param name="writer"></param> protected virtual void Write(MultiPoint multiPoint, XmlTextWriter writer) { writer.WriteStartElement("MultiPoint"); for (int i = 0; i < multiPoint.NumGeometries; i++) { writer.WriteStartElement("pointMember"); Write(multiPoint.Geometries[i] as Point, writer); writer.WriteEndElement(); } writer.WriteEndElement(); }
public static void DrawMultiPoint(IPointSymbolizer symbolizer, Graphics g, MultiPoint points, Map map) { symbolizer.Render(map, points, g); }
public void One_null_multipoint_should_not_equal_a_none_null_multipoint() { MultiPoint multiPoint = new MultiPoint(), other = null; (multiPoint == other).Should().BeFalse(); }
public void Two_null_multipoints_should_equal() { MultiPoint multiPoint = null, other = null; (multiPoint == other).Should().BeTrue(); }
public void If_multipoint_is_not_initial_then_it_should_be_invalid() { var multiPoint = new MultiPoint(); multiPoint.IsValid.Should().BeFalse(); }
public void One_valid_multipoint_should_equal_to_itself() { var multiPoint = new MultiPoint(new[] { new Point(100, 90) }); multiPoint.Equals(multiPoint).Should().BeTrue(); }
public void If_multipoint_with_valid_latlng_then_it_should_be_valid() { var multiPoint = new MultiPoint(new[] { new Point(-170.1, 90), new Point(120, -70) }); multiPoint.IsValid.Should().BeTrue(); }
public void If_multipoint_with_out_of_range_latlng_then_it_should_be_invalid(double longitude, double latitude) { var multiPoint = new MultiPoint(new[] { new Point(longitude, latitude) }); multiPoint.IsValid.Should().BeFalse(); }
private static MultiPoint readMultiPoint(WktStreamTokenizer tokenizer) { tokenizer.ReadToken("("); List<ICoordinate> points = new List<ICoordinate>(); while (true) { points.Add(readPoint(tokenizer).Coordinate); tokenizer.NextToken(true); if (tokenizer.GetStringValue() == ",") continue; if (tokenizer.GetStringValue() == ")") break; } if (tokenizer.GetStringValue() == ")") { MultiPoint multiPoint = new MultiPoint(points); return multiPoint; } else throwMissingCloseBracket(tokenizer); return null; }
private static IGeometry getMultiPointBuffer(MultiPoint multiPoint, double distance, int pointsPerCircle, bool allowParallels) { Polygon temp = new Polygon(); List<Polygon> partialBuffers = new List<Polygon>(); ICollection<IGeometry> gc; int c = 0; foreach (ICoordinate p in multiPoint.Points) { gc = temp.Union(getCoordinateBuffer(p, distance, pointsPerCircle)); if (gc.Count > 0) temp = (Polygon)((GeometryCollection)gc)[0]; c++; if (c == 3) { partialBuffers.Add(temp); temp = new Polygon(); c = 0; } } if (temp.CoordinateCount > 0) partialBuffers.Add(temp); return mergePartialBuffers(partialBuffers, allowParallels); }
public EntityFrameworkConvertTests() { point = new Point(new Position(53.2455662, 90.65464646)); multiPoint = new MultiPoint(new List <Point> { new Point(new Position(52.379790828551016, 5.3173828125)), new Point(new Position(52.36721467920585, 5.456085205078125)), new Point(new Position(52.303440474272755, 5.386047363281249, 4.23)) }); lineString = new LineString(new List <IPosition> { new Position(52.379790828551016, 5.3173828125), new Position(52.36721467920585, 5.456085205078125), new Position(52.303440474272755, 5.386047363281249, 4.23) }); multiLineString = new MultiLineString(new List <LineString> { new LineString(new List <IPosition> { new Position(52.379790828551016, 5.3173828125), new Position(52.36721467920585, 5.456085205078125), new Position(52.303440474272755, 5.386047363281249, 4.23) }), new LineString(new List <IPosition> { new Position(52.379790828551016, 5.3273828125), new Position(52.36721467920585, 5.486085205078125), new Position(52.303440474272755, 5.426047363281249, 4.23) }) }); /* * POLYGON ( * new Position(5.6718750056992775 43.179268827576763), * new Position(5.7627938771963274 43.282358019007539), * new Position(5.6827878158334473 43.399165901196014), * new Position(5.7883490332690677 43.420263481346808), * new Position(5.6569195891695419 43.575280226136485), * new Position(5.7992059672926253 43.659928964120652), * new Position(5.772453944482355 43.722182053435269), * new Position(5.5305079449053451 43.659231446664869), * new Position(4.7390611308576647 43.924068511657794), * new Position(4.641909591242106 43.867477587972004), * new Position(4.6268107341244811 43.688132623094383), * new Position(4.4864081749462246 43.698853136943086), * new Position(4.4608683979209367 43.58945970637793), * new Position(4.2379330762447731 43.49708004345662), * new Position(4.55238424144851 43.446971295015622), * new Position(4.6618166942350943 43.346294896388663), * new Position(4.8579247842437638 43.334654947962143), * new Position(4.861467735270022 43.455412079597927), * new Position(5.0545884574514082 43.326670147834825), * new Position(5.3160671845314269 43.359760733800755), * new Position(5.3405286722678431 43.214414007811236), * new Position(5.6718750056992775 43.179268827576763), * * new Position(5.0144408111937375, 43.555545986597537), * new Position( 5.2267178460469337, 43.453922302237586), * new Position( 5.0599489280101588, 43.404914999013144), * new Position(5.0144408111937375, 43.555545986597537) */ polygonWithHole = new Polygon(new List <LineString> { new LineString(new List <Position> { new Position(43.179268827576763, 5.6718750056992775), new Position(43.282358019007539, 5.7627938771963274), new Position(43.399165901196014, 5.6827878158334473), new Position(43.420263481346808, 5.7883490332690677), new Position(43.575280226136485, 5.6569195891695419), new Position(43.659928964120652, 5.7992059672926253), new Position(43.722182053435269, 5.772453944482355), new Position(43.659231446664869, 5.5305079449053451), new Position(43.924068511657794, 4.7390611308576647), new Position(43.867477587972004, 4.641909591242106), new Position(43.688132623094383, 4.6268107341244811), new Position(43.698853136943086, 4.4864081749462246), new Position(43.58945970637793, 4.4608683979209367), new Position(43.49708004345662, 4.2379330762447731), new Position(43.446971295015622, 4.55238424144851), new Position(43.346294896388663, 4.6618166942350943), new Position(43.334654947962143, 4.8579247842437638), new Position(43.455412079597927, 4.861467735270022), new Position(43.326670147834825, 5.0545884574514082), new Position(43.359760733800755, 5.3160671845314269), new Position(43.214414007811236, 5.3405286722678431), new Position(43.179268827576763, 5.6718750056992775) }), new LineString(new List <Position> { new Position(43.555545986597537, 5.0144408111937375), new Position(43.453922302237586, 5.2267178460469337), new Position(43.404914999013144, 5.0599489280101588), new Position(43.555545986597537, 5.0144408111937375) }) }); polygonWithHoleReverseWinding = new Polygon(new List <LineString> { new LineString(polygonWithHole.Coordinates[0].Coordinates.Select(c => (Position)c).Reverse().ToList()), new LineString(polygonWithHole.Coordinates[1].Coordinates.Select(c => (Position)c).Reverse().ToList()) }); polygon = new Polygon(new List <LineString> { new LineString(new List <Position> { new Position(52.379790828551016, 5.3173828125), new Position(52.303440474272755, 5.386047363281249, 4.23), new Position(52.36721467920585, 5.456085205078125), new Position(52.379790828551016, 5.3173828125) }) }); multiPolygon = new MultiPolygon(new List <Polygon> { new Polygon(new List <LineString> { new LineString(new List <IPosition> { new Position(52.959676831105995, -2.6797102391514338), new Position(52.930592009390175, -2.6548779332193022), new Position(52.89564268523565, -2.6931334629377890), new Position(52.878791122091066, -2.6932445076063951), new Position(52.875255907042678, -2.6373482332006359), new Position(52.882954723868622, -2.6050779098387191), new Position(52.875476700983896, -2.5851645010668989), new Position(52.891287242948195, -2.5815104708998668), new Position(52.908449372833715, -2.6079763270327119), new Position(52.9608756693609, -2.6769029474483279), new Position(52.959676831105995, -2.6797102391514338), }) }), new Polygon(new List <LineString> { new LineString(new List <IPosition> { new Position(52.89610842810761, -2.69628632041613), new Position(52.926572918779222, -2.6996509024137052), new Position(52.920394929466184, -2.772273870352612), new Position(52.937353122653533, -2.7978187468478741), new Position(52.94013913205788, -2.838979264607087), new Position(52.929801009654575, -2.83848602260174), new Position(52.90253773227807, -2.804554822840895), new Position(52.89938894657412, -2.7663172788742449), new Position(52.8894641454077, -2.75901233808515), new Position(52.89610842810761, -2.69628632041613) }) }) }); geomCollection = new GeometryCollection(new List <IGeometryObject> { point, multiPoint, lineString, multiLineString, polygon, multiPolygon }); feature = new Feature.Feature(polygon, new Dictionary <string, object>() { { "Key", "Value" } }, "Id"); featureCollection = new FeatureCollection(new List <Feature.Feature> { feature, new Feature.Feature(multiPolygon, null) }); }
protected MultiPoint ReadMultiPoint(Dimension dimension) { ExpectGroupStart(); MultiPoint multiPoint = new MultiPoint(MatchCoordinates(dimension)); multiPoint.Dimension = dimension; ExpectGroupEnd(); return multiPoint; }
/// <summary> /// Converts a MultiPoint to <MultiPoint Tagged Text> /// format, then Appends it to the writer. /// </summary> /// <param name="multipoint">The MultiPoint to process.</param> /// <param name="writer">The output writer to Append to.</param> protected void AppendMultiPointTaggedText(MultiPoint multipoint, TextWriter writer) { //writer.Write("<g>"); AppendMultiPointText(multipoint, writer); //writer.Write("</g>"); }
void addInput(ESRI.ArcGIS.Client.Geometry.Geometry geometry) { GraphicsLayer layer = getLayer(); #region Create layer if not already there and add to map if (layer == null) { InputLayerID = Guid.NewGuid().ToString("N"); layer = new GraphicsLayer(); if (config.Layer != null) { layer.Renderer = config.Layer.Renderer; Core.LayerExtensions.SetFields(layer, Core.LayerExtensions.GetFields(config.Layer)); Core.LayerExtensions.SetGeometryType(layer, Core.LayerExtensions.GetGeometryType(config.Layer)); Core.LayerExtensions.SetDisplayField(layer, Core.LayerExtensions.GetDisplayField(config.Layer)); Core.LayerExtensions.SetPopUpsOnClick(layer, Core.LayerExtensions.GetPopUpsOnClick(config.Layer)); LayerProperties.SetIsPopupEnabled(layer, LayerProperties.GetIsPopupEnabled(config.Layer)); } layer.ID = InputLayerID; layer.SetValue(MapApplication.LayerNameProperty, string.IsNullOrEmpty(config.LayerName) ? string.IsNullOrEmpty(config.Label) ? config.Name : config.Label : config.LayerName); layer.Opacity = config.Opacity; Map.Layers.Add(layer); } #endregion #region Add geometry to layer if (config.GeometryType == Core.GeometryType.MultiPoint) // Special handling for MultiPoint geometry { if (layer.Graphics.Count == 0) { // Create a new MultiPoint geometry and add the passed-in point to it var multipoint = new MultiPoint() { SpatialReference = geometry.SpatialReference }; multipoint.Points.Add((MapPoint)geometry); var g = new Graphic() { Geometry = multipoint }; layer.Graphics.Add(g); } else { // Get the sketch graphic's MultiPoint geometry and add the passed-in point to it var multipoint = (MultiPoint)layer.Graphics[0].Geometry; multipoint.Points.Add((MapPoint)geometry); layer.Refresh(); } } else { Graphic g = new Graphic() { Geometry = geometry }; layer.Graphics.Add(g); } #endregion }
public void TestGeometryCollectionSerialization() { var geometry1 = new LineString( new GeoCoordinate[] { new GeoCoordinate(0, 0), new GeoCoordinate(0, 1), new GeoCoordinate(1, 1), new GeoCoordinate(1, 0) }); var geometry2 = new LineString( new GeoCoordinate[] { new GeoCoordinate(0, 0), new GeoCoordinate(0, 2), new GeoCoordinate(2, 2), new GeoCoordinate(2, 0) }); var geometry3 = new LineString( new GeoCoordinate[] { new GeoCoordinate(0, 0), new GeoCoordinate(0, 3), new GeoCoordinate(3, 3), new GeoCoordinate(3, 0) }); var geometry4 = new LineairRing( new GeoCoordinate[] { new GeoCoordinate(0, 0), new GeoCoordinate(0, 1), new GeoCoordinate(1, 1), new GeoCoordinate(1, 0), new GeoCoordinate(0, 0) }); var geometry5 = new Polygon(new LineairRing( new GeoCoordinate[] { new GeoCoordinate(0, 0), new GeoCoordinate(0, 1), new GeoCoordinate(1, 1), new GeoCoordinate(1, 0), new GeoCoordinate(0, 0) })); var geometry6 = new MultiPolygon(geometry5, new Polygon(new LineairRing( new GeoCoordinate[] { new GeoCoordinate(0, 0), new GeoCoordinate(0, 2), new GeoCoordinate(2, 2), new GeoCoordinate(2, 0), new GeoCoordinate(0, 0) }))); var geometry7 = new Point(new GeoCoordinate(0, 1)); var geometry8 = new MultiPoint(geometry7, new Point(new GeoCoordinate(0, 2))); var geometryCollection = new GeometryCollection( geometry1, geometry2, geometry3, geometry4, geometry5, geometry6, geometry7, geometry8); var serialized = geometryCollection.ToGeoJson(); serialized = serialized.RemoveWhitespace(); Assert.AreEqual("{\"type\":\"GeometryCollection\",\"geometries\":[{\"type\":\"LineString\",\"coordinates\":[[0.0,0.0],[1.0,0.0],[1.0,1.0],[0.0,1.0]]},{\"type\":\"LineString\",\"coordinates\":[[0.0,0.0],[2.0,0.0],[2.0,2.0],[0.0,2.0]]},{\"type\":\"LineString\",\"coordinates\":[[0.0,0.0],[3.0,0.0],[3.0,3.0],[0.0,3.0]]},{\"type\":\"Polygon\",\"coordinates\":[[[0.0,0.0],[1.0,0.0],[1.0,1.0],[0.0,1.0],[0.0,0.0]]]},{\"type\":\"Polygon\",\"coordinates\":[[[0.0,0.0],[1.0,0.0],[1.0,1.0],[0.0,1.0],[0.0,0.0]]]},{\"type\":\"MultiPolygon\",\"coordinates\":[[[[0.0,0.0],[1.0,0.0],[1.0,1.0],[0.0,1.0],[0.0,0.0]]],[[[0.0,0.0],[2.0,0.0],[2.0,2.0],[0.0,2.0],[0.0,0.0]]]]},{\"type\":\"Point\",\"coordinates\":[1.0,0.0]},{\"type\":\"MultiPoint\",\"coordinates\":[[1.0,0.0],[2.0,0.0]]}]}", serialized); }
/// <summary> /// Writes a multipoint. /// </summary> /// <param name="mp">The multipoint to be written.</param> /// <param name="bWriter">Stream to write to.</param> /// <param name="byteorder">Byte order</param> private static void WriteMultiPoint(MultiPoint mp, BinaryWriter bWriter, WkbByteOrder byteorder) { //Write the number of points. WriteUInt32((uint) mp.Points.Count, bWriter, byteorder); //Loop on the number of points. foreach (var p in mp.Points) { //Write Points Header bWriter.Write((byte) byteorder); WriteUInt32((uint) WKBGeometryType.WKBPoint, bWriter, byteorder); //Write each point. WritePoint(p, bWriter, byteorder); } }
/// <summary> /// /// </summary> /// <param name="multiPoint"></param> /// <returns></returns> protected int SetByteStreamLength(MultiPoint multiPoint) { int numPoints = multiPoint.NumPoints; return(CalculateLength(numPoints)); }
private void WriteMultiPoint(MultiPoint multiPoint) { wktBuilder.Append("("); WriteWktCoordinates(multiPoint.Points); wktBuilder.Append(")"); }
private static void MultiPointAreEqual(MultiPoint expected, MultiPoint actual) { Assert.AreEqual(expected.Points.Count, actual.Points.Count); }
private GeometryCollection calculateOverlay(IGeometry geometry1, IGeometry geometry2, OverlayType operation, bool performSnapping) { GeometryCollection result = new GeometryCollection(); if (geometry1 == null && geometry2 == null) return result; if (geometry2 == null) { if (operation != OverlayType.Intersection) result.Add((IGeometry)geometry1.Clone()); return result; } if (geometry1 == null) { if (operation == OverlayType.Intersection || operation == OverlayType.Difference) return result; result.Add((IGeometry)geometry2.Clone()); return result; } // If the bounding rectangles do not intersect, the result of all operations can be obtained easily BoundingRectangle br1 = geometry1.GetBoundingRectangle(); BoundingRectangle br2 = geometry2.GetBoundingRectangle(); if(!br1.IsEmpty()) br1.Grow(PlanimetryAlgorithms.Tolerance); if (!br2.IsEmpty()) br2.Grow(PlanimetryAlgorithms.Tolerance); if (!br1.Intersects(br2)) return calculateNonIntersectedObjectsOverlay(geometry1, geometry2, operation, performSnapping); // easier to convert the point-to-multipoint to preserve generality if (geometry1 is PointD) { PointD p = (PointD)geometry1.Clone(); geometry1 = new MultiPoint(new ICoordinate[] { p.Coordinate }); } if (geometry2 is PointD) { PointD p = (PointD)geometry2.Clone(); geometry2 = new MultiPoint(new ICoordinate[] { p.Coordinate }); } int minDim = Math.Min((int)geometry1.Dimension, (int)geometry2.Dimension); int maxDim = Math.Max((int)geometry1.Dimension, (int)geometry2.Dimension); // overlay calculation points if (minDim == 0 && maxDim == 0) getPointPointOverlay((MultiPoint)geometry1, (MultiPoint)geometry2, operation, result); // calculation overlay polylines if (minDim == 1 && maxDim == 1) getPolylinePolylineOverlay((Polyline)geometry1, (Polyline)geometry2, operation, result, false); // calculation of polygon overlay if (minDim == 2 && maxDim == 2) getPolygonPolygonOverlay((Polygon)geometry1, (Polygon)geometry2, operation, result, false); // calculation overlay points and polylines if (minDim == 0 && maxDim == 1) { if (geometry1 is MultiPoint) getPointPolylineOverlay((MultiPoint)geometry1, (Polyline)geometry2, operation, result, false, false); else getPointPolylineOverlay((MultiPoint)geometry2, (Polyline)geometry1, operation, result, false, true); } // calculation point and polygon overlay if (minDim == 0 && maxDim == 2) { if (geometry1 is MultiPoint) getPointPolygonOverlay((MultiPoint)geometry1, (Polygon)geometry2, operation, result, false, false); else getPointPolygonOverlay((MultiPoint)geometry2, (Polygon)geometry1, operation, result, false, true); } // calculation overlay polylines and polygons if (minDim == 1 && maxDim == 2) { if (geometry1 is Polyline) getPolylinePolygonOverlay((Polyline)geometry1, (Polygon)geometry2, operation, result, false, false); else getPolylinePolygonOverlay((Polyline)geometry2, (Polygon)geometry1, operation, result, false, true); } return result; }
public void test_GetBoundary() { //try on a simple-open linestring LineString ls = SimpleOpen(); Geometry geom = ls.GetBoundary(); Assertion.AssertEquals("GetBoundary-1: ", false, geom.IsEmpty()); Assertion.AssertEquals("GetBoundary-2: ", 2, geom.GetNumPoints()); GeometryFactory gf = new GeometryFactory(_precMod, _sRID); MultiPoint mp = gf.CreateMultiPoint(geom.GetCoordinates()); for (int i = 0; i < mp.GetNumPoints(); i++) { switch (i) { case 0: Assertion.AssertEquals("GetBoundary-3: ", 1.0, mp.GetCoordinate(i).X); Assertion.AssertEquals("GetBoundary-4: ", 1.0, mp.GetCoordinate(i).Y); break; case 1: Assertion.AssertEquals("GetBoundary-5: ", 9.0, mp.GetCoordinate(i).X); Assertion.AssertEquals("GetBoundary-6: ", 22.0, mp.GetCoordinate(i).Y); break; default: Assertion.Fail("This should never be reached"); break; } } //try on a simple-closed linestring ls = SimpleClosed(); geom = ls.GetBoundary(); Assertion.AssertEquals("GetBoundary-7: ", true, geom.IsEmpty()); Assertion.AssertEquals("GetBoundary-8: ", 0, geom.GetNumPoints()); //try on a nonsimple-open linestring ls = NonSimpleOpen(); geom = ls.GetBoundary(); Assertion.AssertEquals("GetBoundary-9: ", false, geom.IsEmpty()); Assertion.AssertEquals("GetBoundary-10: ", 2, geom.GetNumPoints()); mp = gf.CreateMultiPoint(geom.GetCoordinates()); for (int i = 0; i < mp.GetNumPoints(); i++) { switch (i) { case 0: Assertion.AssertEquals("GetBoundary-11: ", 2.0, mp.GetCoordinate(i).X); Assertion.AssertEquals("GetBoundary-12: ", 2.0, mp.GetCoordinate(i).Y); break; case 1: Assertion.AssertEquals("GetBoundary-13: ", 3.0, mp.GetCoordinate(i).X); Assertion.AssertEquals("GetBoundary-14: ", 9.0, mp.GetCoordinate(i).Y); break; default: Assertion.Fail("This should never be reached"); break; } } //try on a simple-closed linestring ls = NonSimpleClosed(); geom = ls.GetBoundary(); Assertion.AssertEquals("GetBoundary-15: ", true, geom.IsEmpty()); Assertion.AssertEquals("GetBoundary-16: ", 0, geom.GetNumPoints()); }
/// <summary> /// Deserializes an instance of MapAround.Geometry.MultiPoint from the specified stream. /// </summary> /// <param name="stream">A stream containing the multipoint geometry</param> /// <returns>Deserialized instance of MapAround.Geometry.MultiPoint</returns> public static MultiPoint DeserializeMultiPoint(Stream stream) { int partLength = readInt(stream); MultiPoint multiPoint = new MultiPoint(); for (int j = 0; j < partLength; j++) { double x = readDouble(stream); double y = readDouble(stream); multiPoint.Points.Add(PlanimetryEnvironment.NewCoordinate(x, y)); } return multiPoint; }
/// <summary> /// Converts a MultiPoint to <MultiPoint Tagged Text> /// format, then Appends it to the writer. /// </summary> /// <param name="MultiPoint">The MultiPoint to process.</param> /// <param name="writer">The output writer to Append to.</param> private static void AppendMultiPointTaggedText(MultiPoint MultiPoint, StringWriter writer) { writer.Write("MultiPoint "); AppendMultiPointText(MultiPoint, writer); }
/// <summary> /// Computes a well-known text representation /// of the multipoint geometry. /// </summary> /// <param name="multiPoint">An instance of MapAround.Geometry.MultiPoint to setialize</param> /// <returns>A well-known text representation of specified geometry.</returns> public static string GetMultiPointWKT(MultiPoint multiPoint) { StringBuilder sb = new StringBuilder("MultiPoint ("); IList<ICoordinate> points = multiPoint.Points; int cnt = points.Count; for (int i = 0; i < cnt - 1; i++) sb.Append("(" + pointCoordsString(points[i]) + "), "); sb.Append("(" + pointCoordsString(points[cnt - 1]) + "))"); return sb.ToString(); }
private object Transform2D_(object geometry, IntPtr from, IntPtr to, bool fromProjective, bool toProjektive) { if (geometry == null) { return(null); } if (from == IntPtr.Zero || to == IntPtr.Zero) { return(geometry); } if (geometry is PointCollection) { PointCollection pColl = (PointCollection)geometry; int pointCount = pColl.PointCount; if (pointCount == 0) { return(geometry); } IntPtr buffer = Marshal.AllocHGlobal(pointCount * 2 * sizeof(double)); lock (LockThis1) { try { IntPtr xPtr = IntPtr.Zero, yPtr = IntPtr.Zero; unsafe { double *b = (double *)buffer; for (int i = 0; i < pointCount; i++) { b[i] = pColl[i].X; b[pointCount + i] = pColl[i].Y; } if (!fromProjective) { ToRad(buffer, pointCount * 2); } xPtr = (IntPtr)(&b[0]); yPtr = (IntPtr)(&b[pointCount]); } if (from != IntPtr.Zero && to != IntPtr.Zero) { //if (preTo > 0) //{ // Proj4Wrapper.pj_transform(from, preTo, pointCount, 0, xPtr, yPtr, (IntPtr)0); // Proj4Wrapper.pj_transform(preTo, to, pointCount, 0, xPtr, yPtr, (IntPtr)0); //} //else //{ Proj4Wrapper.pj_transform(from, to, pointCount, 0, xPtr, yPtr, IntPtr.Zero); //} } if (!toProjektive) { ToDeg(buffer, pointCount * 2); } IPointCollection target = null; if (pColl is IRing) { target = new Ring(); } else if (pColl is IPath) { target = new Path(); } else if (pColl is IMultiPoint) { target = new MultiPoint(); } else { target = new PointCollection(); } unsafe { double *b = (double *)buffer; for (int i = 0; i < pointCount; i++) { target.AddPoint(new Point(b[i], b[pointCount + i])); } return(target); } } finally { Marshal.FreeHGlobal(buffer); } } //double [] x; //double [] y; //((PointCollection)geometry).getXY(out x,out y); //if (!fromProjective) ToRad(x, y); //if(from>0 && to>0) // Proj4Wrapper.pj_transform(from,to,x.Length,0,x,y,null); //if (!toProjektive) ToDeg(x, y); //if(geometry is Ring) //{ // Ring ring=new Ring(); // ring.setXYZ(x,y,null); // return ring; //} //if(geometry is Path) //{ // Path path=new Path(); // path.setXYZ(x,y,null); // return path; //} //if (geometry is MultiPoint) //{ // MultiPoint multiPoint = new MultiPoint(); // multiPoint.setXYZ(x, y, null); // return multiPoint; //} //return new PointCollection(x,y,null); } if (geometry is IPoint) { double[] x = { ((IPoint)geometry).X }; double[] y = { ((IPoint)geometry).Y }; if (!fromProjective) { ToRad(x, y); } lock (LockThis1) { if (from != IntPtr.Zero && to != IntPtr.Zero) { unsafe { fixed(double *xx = x) fixed(double *yy = y) { IntPtr xPtr = (IntPtr)(xx); IntPtr yPtr = (IntPtr)(yy); //if (preTo > 0) //{ // Proj4Wrapper.pj_transform(from, preTo, x.Length, 0, xPtr, yPtr, (IntPtr)0); // Proj4Wrapper.pj_transform(preTo, to, x.Length, 0, xPtr, yPtr, (IntPtr)0); //} //else //{ Proj4Wrapper.pj_transform(from, to, x.Length, 0, xPtr, yPtr, IntPtr.Zero); //} } } } } if (!toProjektive) { ToDeg(x, y); } return(new Point(x[0], y[0])); } if (geometry is IEnvelope) { return(Transform2D_(((IEnvelope)geometry).ToPolygon(10), from, to, fromProjective, toProjektive)); } if (geometry is IPolyline) { int count = ((IPolyline)geometry).PathCount; IPolyline polyline = new Polyline(); for (int i = 0; i < count; i++) { polyline.AddPath((IPath)Transform2D_(((IPolyline)geometry)[i], from, to, fromProjective, toProjektive)); } return(polyline); } if (geometry is IPolygon) { int count = ((IPolygon)geometry).RingCount; IPolygon polygon = new Polygon(); for (int i = 0; i < count; i++) { polygon.AddRing((IRing)Transform2D_(((IPolygon)geometry)[i], from, to, fromProjective, toProjektive)); } return(polygon); } if (geometry is IAggregateGeometry) { int count = ((IAggregateGeometry)geometry).GeometryCount; IAggregateGeometry aGeom = new AggregateGeometry(); for (int i = 0; i < count; i++) { aGeom.AddGeometry((IGeometry)Transform2D_(((IAggregateGeometry)geometry)[i], from, to, fromProjective, toProjektive)); } return(aGeom); } return(null); }
/// <summary> /// Serializes a multipoint geometry into stream using a specified byte order. /// </summary> /// <param name="stream">A stream instance</param> /// <param name="multiPoint">A multipoint geometry to serialize</param> /// <param name="byteOrder">A byte order which is used to write integer and double values</param> public static void SerializeMultiPoint(Stream stream, MultiPoint multiPoint, WKBByteOrder byteOrder) { // порядок байтов stream.Write(new byte[] { (byte)byteOrder }, 0, sizeof(byte)); // тип геометрической фигуры writeUInt32((uint)WKBGeometryType.MultiPoint, stream, byteOrder); // количество вершин writeUInt32((uint)multiPoint.Points.Count, stream, byteOrder); // вершины foreach (ICoordinate p in multiPoint.Points) { // порядок байтов stream.Write(new byte[] { (byte)byteOrder }, 0, sizeof(byte)); // тип геометрической фигуры writeUInt32((uint)WKBGeometryType.Point, stream, byteOrder); writeDouble(p.X, stream, byteOrder); writeDouble(p.Y, stream, byteOrder); } }
/// <summary> /// Converts a MultiPoint to <MultiPoint Tagged Text> /// format, then Appends it to the writer. /// </summary> /// <param name="multipoint">The MultiPoint to process.</param> /// <param name="level"></param> /// <param name="writer">The output writer to Append to.</param> protected void AppendMultiPointTaggedText(MultiPoint multipoint, int level, StringWriter writer) { writer.Write("MULTIPOINT "); AppendMultiPointText(multipoint, level, writer); }
public void Write_WritesMultiPointsOfAllDimensions(MultiPoint toWrite, string expectedWkt) { this.TestWriteGeometry(toWrite, expectedWkt); }
private static void BuildMultiPoint(StringBuilder builder, MultiPoint multiPoint) { builder.AppendType(GeoJsonTypes.MultiPoint); builder.AppendMultiPoints(multiPoint.Geometries.Select(x => x as Point).ToList()); builder.Append("}"); }
/// <summary> /// /// </summary> /// <param name="multiPoint"></param> /// <returns></returns> protected virtual int SetByteStreamLength(MultiPoint multiPoint) { int count = INIT_VALUE; foreach (Point p in multiPoint.Geometries) count += SetByteStreamLength(p); return count; }
private static MultiPoint CreateWKBMultiPoint(BinaryReader reader, WkbByteOrder byteOrder) { // Get the number of points in this multipoint. var numPoints = (int) ReadUInt32(reader, byteOrder); // Create a new array for the points. var points = new MultiPoint(); // Loop on the number of points. for (var i = 0; i < numPoints; i++) { // Read point header reader.ReadByte(); ReadUInt32(reader, byteOrder); // TODO: Validate type // Create the next point and add it to the point array. points.Points.Add(CreateWKBPoint(reader, byteOrder)); } return points; }
private void WriteMultiPoint(MultiPoint mp, WKBByteOrder byteOrder) { // Write byte order _writer.Write((byte)byteOrder); // Write type this.WriteType(mp, byteOrder); // Get the number of points in this multipoint. int numPoints = mp.getNumPoints(); // Write the number of points. this.Write((uint)numPoints, byteOrder); // Loop on the number of points. for (int i = 0; i < numPoints; i++) { // Write each point. this.WritePoint((Point)mp.getGeometryN(i), byteOrder, true); } }
public ToSqlGeometryTests() { point = new Point(new Position(53.2455662, 90.65464646)); multiPoint = new MultiPoint(new List <Point> { new Point(new Position(52.379790828551016, 5.3173828125)), new Point(new Position(52.36721467920585, 5.456085205078125)), new Point(new Position(52.303440474272755, 5.386047363281249, 4.23)) }); lineString = new LineString(new List <IPosition> { new Position(52.379790828551016, 5.3173828125), new Position(52.36721467920585, 5.456085205078125), new Position(52.303440474272755, 5.386047363281249, 4.23) }); multiLineString = new MultiLineString(new List <LineString> { new LineString(new List <IPosition> { new Position(52.379790828551016, 5.3173828125), new Position(52.36721467920585, 5.456085205078125), new Position(52.303440474272755, 5.386047363281249, 4.23) }), new LineString(new List <IPosition> { new Position(52.379790828551016, 5.3273828125), new Position(52.36721467920585, 5.486085205078125), new Position(52.303440474272755, 5.426047363281249, 4.23) }) }); polygonWithHole = new Polygon(new List <LineString> { new LineString(new List <Position> { new Position(0.516357421875, 47.6415668949958), new Position(0.516357421875, 47.34463879017405), new Position(0.977783203125, 47.22539733216678), new Position(1.175537109375, 47.463611506072866), new Position(0.516357421875, 47.6415668949958) }), new LineString(new List <Position> { new Position(0.630340576171875, 47.54944962456812), new Position(0.630340576171875, 47.49380564962583), new Position(0.729217529296875, 47.482669772098674), new Position(0.731964111328125, 47.53276262898896), new Position(0.630340576171875, 47.54944962456812) }) }); polygon = new Polygon(new List <LineString> { new LineString(new List <Position> { new Position(52.379790828551016, 5.3173828125), new Position(52.36721467920585, 5.456085205078125), new Position(52.303440474272755, 5.386047363281249, 4.23), new Position(52.379790828551016, 5.3173828125) }) }); multiPolygon = new MultiPolygon(new List <Polygon> { new Polygon(new List <LineString> { new LineString(new List <IPosition> { new Position(52.959676831105995, -2.6797102391514338), new Position(52.9608756693609, -2.6769029474483279), new Position(52.908449372833715, -2.6079763270327119), new Position(52.891287242948195, -2.5815104708998668), new Position(52.875476700983896, -2.5851645010668989), new Position(52.882954723868622, -2.6050779098387191), new Position(52.875255907042678, -2.6373482332006359), new Position(52.878791122091066, -2.6932445076063951), new Position(52.89564268523565, -2.6931334629377890), new Position(52.930592009390175, -2.6548779332193022), new Position(52.959676831105995, -2.6797102391514338) }) }), new Polygon(new List <LineString> { new LineString(new List <IPosition> { new Position(52.89610842810761, -2.69628632041613), new Position(52.8894641454077, -2.75901233808515), new Position(52.89938894657412, -2.7663172788742449), new Position(52.90253773227807, -2.804554822840895), new Position(52.929801009654575, -2.83848602260174), new Position(52.94013913205788, -2.838979264607087), new Position(52.937353122653533, -2.7978187468478741), new Position(52.920394929466184, -2.772273870352612), new Position(52.926572918779222, -2.6996509024137052), new Position(52.89610842810761, -2.69628632041613) }) }) }); geomCollection = new GeometryCollection(new List <IGeometryObject> { point, multiPoint, lineString, multiLineString, polygon, multiPolygon }); feature = new Feature.Feature(polygon, new Dictionary <string, object>() { { "Key", "Value" } }, "Id"); featureCollection = new FeatureCollection(new List <Feature.Feature> { feature, new Feature.Feature(multiPolygon, null) }); }
/// <summary> /// Creates a Point using the next token in the stream. /// </summary> /// <param name="tokenizer">Tokenizer over a stream of text in Well-known Text /// format. The next tokens must form a <Point Text>.</param> /// <returns>Returns a Point specified by the next token in /// the stream.</returns> /// <remarks> /// ParseException is thrown if an unexpected token is encountered. /// </remarks> private static MultiPoint ReadMultiPointText(WktStreamTokenizer tokenizer) { MultiPoint mp = new MultiPoint(); string nextToken = GetNextEmptyOrOpener(tokenizer); if (nextToken == "EMPTY") return mp; mp.Points.Add(ReadMapPointText(tokenizer)); nextToken = GetNextCloserOrComma(tokenizer); while (nextToken == ",") { mp.Points.Add(ReadMapPointText(tokenizer)); nextToken = GetNextCloserOrComma(tokenizer); } return mp; }
public void TestMultiPointEqualsHashCode() { var multiPoint1 = new MultiPoint( new[] { new Position(20, 30), new Position(30, 40) }, new GeometryParams { AdditionalProperties = new Dictionary <string, object> { { "a", "b" } }, BoundingBox = new BoundingBox(new Position(0, 0), new Position(40, 40)), Crs = Crs.Named("SomeCrs") }); var multiPoint2 = new MultiPoint( new[] { new Position(20, 30), new Position(30, 40) }, new GeometryParams { AdditionalProperties = new Dictionary <string, object> { { "a", "b" } }, BoundingBox = new BoundingBox(new Position(0, 0), new Position(40, 40)), Crs = Crs.Named("SomeCrs") }); var multiPoint3 = new MultiPoint( new[] { new Position(20, 30), new Position(31, 40) }, new GeometryParams { AdditionalProperties = new Dictionary <string, object> { { "a", "b" } }, BoundingBox = new BoundingBox(new Position(0, 0), new Position(40, 40)), Crs = Crs.Named("SomeCrs") }); var multiPoint4 = new MultiPoint( new[] { new Position(20, 30), new Position(30, 40) }, new GeometryParams { AdditionalProperties = new Dictionary <string, object> { { "b", "c" } }, BoundingBox = new BoundingBox(new Position(0, 0), new Position(40, 40)), Crs = Crs.Named("SomeCrs") }); var multiPoint5 = new MultiPoint( new[] { new Position(20, 30), new Position(30, 40) }, new GeometryParams { AdditionalProperties = new Dictionary <string, object> { { "a", "b" } }, BoundingBox = new BoundingBox(new Position(0, 0), new Position(40, 41)), Crs = Crs.Named("SomeCrs") }); var multiPoint6 = new MultiPoint( new[] { new Position(20, 30), new Position(30, 40) }, new GeometryParams { AdditionalProperties = new Dictionary <string, object> { { "a", "b" } }, BoundingBox = new BoundingBox(new Position(0, 0), new Position(40, 40)), Crs = Crs.Named("SomeCrs1") }); Assert.AreEqual(multiPoint1, multiPoint2); Assert.AreEqual(multiPoint1.GetHashCode(), multiPoint2.GetHashCode()); Assert.AreNotEqual(multiPoint1, multiPoint3); Assert.AreNotEqual(multiPoint1.GetHashCode(), multiPoint3.GetHashCode()); Assert.AreNotEqual(multiPoint1, multiPoint4); Assert.AreNotEqual(multiPoint1.GetHashCode(), multiPoint4.GetHashCode()); Assert.AreNotEqual(multiPoint1, multiPoint5); Assert.AreNotEqual(multiPoint1.GetHashCode(), multiPoint5.GetHashCode()); Assert.AreNotEqual(multiPoint1, multiPoint6); Assert.AreNotEqual(multiPoint1.GetHashCode(), multiPoint6.GetHashCode()); }
private void WriteMultiPoint(MultiPoint multiPoint) { wkbWriter.Write(multiPoint.Points.Count); foreach (Point point in multiPoint.Points) WriteInternal(point, multiPoint); }
static public IGeometry ToGeometry(this JsonGeometry geometry) { if (geometry == null) { return(null); } IGeometry shape = null; if (geometry.X.HasValue && geometry.Y.HasValue) { shape = new Point(geometry.X.Value, geometry.Y.Value); } else if (geometry.XMin.HasValue && geometry.YMin.HasValue && geometry.XMax.HasValue && geometry.YMax.HasValue) { shape = new Envelope(geometry.XMin.Value, geometry.YMin.Value, geometry.XMax.Value, geometry.YMax.Value); } else if (geometry.Paths != null && geometry.Paths.Length > 0) { var polyline = new Polyline(); for (int p = 0, pathCount = geometry.Paths.Length; p < pathCount; p++) { var jsonPath = geometry.Paths[p]; if (jsonPath.Length < 1) { continue; } var path = new Path(); for (int i = 0, pointCount = jsonPath.GetLength(0); i < pointCount; i++) { path.AddPoint(new Point(jsonPath[i, 0].Value, jsonPath[i, 1].Value)); } polyline.AddPath(path); } shape = polyline; } else if (geometry.Rings != null && geometry.Rings.Length > 0) { var polygon = new Polygon(); for (int p = 0, ringCount = geometry.Rings.Length; p < ringCount; p++) { var jsonRing = geometry.Rings[p]; if (jsonRing.Length < 1) { continue; } var ring = new Ring(); for (int i = 0, pointCount = jsonRing.GetLength(0); i < pointCount; i++) { ring.AddPoint(new Point(jsonRing[i, 0].Value, jsonRing[i, 1].Value)); } polygon.AddRing(ring); } shape = polygon; } else if (geometry.Points != null && geometry.Points.Length > 0) { var multiPoint = new MultiPoint(); for (int p = 0, pointCount = geometry.Points.Length; p < pointCount; p++) { var point = geometry.Points[p]; if (point != null && point.Length >= 2) { multiPoint.AddPoint(new Point(point[0].Value, point[1].Value)); } } shape = multiPoint; } if (shape != null && geometry.SpatialReference != null && geometry.SpatialReference.Wkid > 0) { shape.Srs = geometry.SpatialReference.Wkid; } return(shape); }
static string GeometryToWktString(MultiPoint multiPoint) { return string.Format("({0})", string.Join(",", multiPoint.Points.Select(GeometryToWktString))); }
private static void AppendMultiPointTaggedText(MultiPoint multipoint, StringWriter writer) { writer.Write("MULTIPOINT "); AppendMultiPointText(multipoint, writer); }
/// <summary> /// Converts a MultiPoint to <MultiPoint Text> format, then /// Appends it to the writer. /// </summary> /// <param name="multiPoint">The MultiPoint to process.</param> /// <param name="level"></param> /// <param name="writer">The output stream writer to Append to.</param> protected void AppendMultiPointText(MultiPoint multiPoint, int level, StringWriter writer) { if ( multiPoint.isEmpty() ) { writer.Write("EMPTY"); } else { writer.Write("("); for (int i = 0; i < multiPoint.getNumGeometries(); i++) { if (i > 0) { writer.Write(", "); } AppendCoordinate( multiPoint.getCoordinates()[i], writer, multiPoint.getPrecisionModel()); } writer.Write(")"); } }
public void TestGeoJson() { Point pt1 = new Point(100, 100); Point pt2 = new Point(200, 200); Point pt3 = new Point(300, 300); MultiPoint pts = new MultiPoint(); pts.Geometries.Add(pt1); pts.Geometries.Add(pt2); pts.Geometries.Add(pt3); var testDto1 = new TestDto() { Id = 1, Geometry = pt1, Name = "MyName" }; var feature1 = new Feature <TestDto>(testDto1); var testDto2 = new TestDto() { Id = 2, Geometry = pt2, Name = "MyName2" }; var feature2 = new Feature <TestDto>(testDto2); JsonSerializerSettings geoJsonSetting = new JsonSerializerSettings() { ContractResolver = FeatuerGeometryResolver.Instance }; //geoJsonSetting.Converters.Add(new GeometryConverter()); //var jsonPt = JsonConvert.SerializeObject(pt1, geoJsonSetting); var features = new FeatureCollection <TestDto>(new List <Feature <TestDto> >() { feature1, feature2 }); var json = JsonConvert.SerializeObject(features, geoJsonSetting); LineString lineString = new LineString(pts.Geometries); var jsonLineString = JsonConvert.SerializeObject(lineString, new GeometryConverter()); var externRing = new List <Point>() { new Point(100.0, 0.0), new Point(101.0, 0.0), new Point(101.0, 1.0), new Point(100.0, 1.0), new Point(100.0, 0.0) }; var holeRing = new List <Point>() { new Point(100.2, 0.2), new Point(100.8, 0.2), new Point(100.8, 0.8), new Point(100.2, 0.8), new Point(100.2, 0.2) }; Polygon polygon = new Polygon(externRing); polygon.InteriorRings.Add(new LinearRing(holeRing)); var jsonPloygon = JsonConvert.SerializeObject(polygon, new GeometryConverter()); }
public static void Write(MultiPoint points, JsonTextWriter writer) { if (points == null) return; if (writer == null) throw new ArgumentNullException("writer", "A valid JSON writer object is required"); writer.WriteStartObject(); writer.WritePropertyName("type"); writer.WriteValue("MultiPoint"); writer.WritePropertyName("coordinates"); writer.WriteStartArray(); foreach (Point entry in points) WriteCoord(entry, writer); writer.WriteEndArray(); writer.WriteEndObject(); }
public MultiPoint GetEchoMultiPoint(MultiPoint geom) { return(geom); }
/// <summary> /// This function lets the user set up whether the shape should be regular, type M or type Z. /// This will not interfere with existing shapes in the geometry, but will simply /// add the specified geometry to the end of the existing information. Sending a null shape /// will create a new shape of the appropriate kind. /// </summary> /// <param name="geom">A Geometries.Geometry specifying what to append to the shape. /// Simply returns mwShape unchanged if geom is null.</param> /// <param name="mwShape">An existing shape with a shapetype already specified.</param> public static void AppendGeometryToShape(IGeometry geom, ref MapWinGIS.Shape mwShape) { // we don't need to throw an error if geom is null, there is simply nothing to add. if (geom == null) { return; } // If we have to set up a new shape object, we will also have to specify a shape type. bool SpecifyShapeType = false; if (mwShape == null) { mwShape = new MapWinGIS.Shape(); SpecifyShapeType = true; } MapWinGIS.Point mwPoint; int rfPt = mwShape.numPoints; // Flexible Point Index int rfPrt = mwShape.NumParts; // Flexible Part Index if (rfPt > 0 && rfPrt == 0) { //Change single part to a multipart shapefile mwShape.InsertPart(0, ref rfPrt); rfPrt++; } #region -------------------------- POINT ------------------------------------------- if (geom.GetType() == typeof(Point)) { if (SpecifyShapeType == true) { mwShape.ShapeType = MapWinGIS.ShpfileType.SHP_POINT; } // Only allow appending to a point shape type if there isn't a point defined yet. if ((mwShape.ShapeType == MapWinGIS.ShpfileType.SHP_MULTIPOINT || mwShape.ShapeType == MapWinGIS.ShpfileType.SHP_MULTIPOINTM || mwShape.ShapeType == MapWinGIS.ShpfileType.SHP_MULTIPOINTZ) || ((mwShape.ShapeType == MapWinGIS.ShpfileType.SHP_POINT || mwShape.ShapeType == MapWinGIS.ShpfileType.SHP_POINTM || mwShape.ShapeType == MapWinGIS.ShpfileType.SHP_POINTZ) && rfPt == 0)) { Point newPoint = geom as Point; mwPoint = new MapWinGIS.Point(); mwPoint.x = newPoint.X; mwPoint.y = newPoint.Y; mwShape.InsertPoint(mwPoint, ref rfPt); return; } else { if ((mwShape.ShapeType == MapWinGIS.ShpfileType.SHP_POINT || mwShape.ShapeType == MapWinGIS.ShpfileType.SHP_POINTM || mwShape.ShapeType == MapWinGIS.ShpfileType.SHP_POINTZ)) { throw new ArgumentException("The Shape type of mwShape must be MultiPoint, MultiPointM, or MultiPointZ in order to Append a Point Geometry to a shape that already contains a point."); } else { throw new ArgumentException("mwShape had a shape type that did not correspond to Point or MultiPoint. Point geometry not added."); } } } #endregion #region -------------------------- MULTI POINT-------------------------------------- if (geom.GetType() == typeof(MultiPoint)) { if (SpecifyShapeType == true) { mwShape.ShapeType = MapWinGIS.ShpfileType.SHP_MULTIPOINT; } if (mwShape.ShapeType == MapWinGIS.ShpfileType.SHP_MULTIPOINT || mwShape.ShapeType == MapWinGIS.ShpfileType.SHP_MULTIPOINTM || mwShape.ShapeType == MapWinGIS.ShpfileType.SHP_MULTIPOINTZ) { MultiPoint newPoints = geom as MultiPoint; for (int iPoint = 0; iPoint < newPoints.Count; iPoint++) { Point CurPoint = newPoints.Geometries[iPoint] as Point; mwPoint = new MapWinGIS.Point(); mwPoint.x = CurPoint.X; mwPoint.y = CurPoint.Y; mwShape.InsertPoint(mwPoint, ref rfPt); rfPt++; // I don't think we can have multi-parts in a multipoint shape } return; } else { throw new ArgumentException("The shape type must be one of the multipoint types to add a multipoint geometry."); } } #endregion #region -------------------------- LINE STRING ------------------------------------- if (geom.GetType() == typeof(LineString) || geom.GetType() == typeof(LinearRing)) { if (SpecifyShapeType == true) { mwShape.ShapeType = MapWinGIS.ShpfileType.SHP_POLYLINE; } if (mwShape.ShapeType == MapWinGIS.ShpfileType.SHP_POLYLINE || mwShape.ShapeType == MapWinGIS.ShpfileType.SHP_POLYLINEM || mwShape.ShapeType == MapWinGIS.ShpfileType.SHP_POLYLINEZ) { LineString newPoints = geom as LineString; // Polymorphism should allow linear rings to be line strings for (int iPoint = 0; iPoint < newPoints.Count; iPoint++) { ICoordinate CurPoint = newPoints.Coordinates[iPoint]; mwPoint = new MapWinGIS.Point(); mwPoint.x = CurPoint.X; mwPoint.y = CurPoint.Y; mwShape.InsertPoint(mwPoint, ref rfPt); rfPt++; // I don't think we can have multi-parts in a multipoint shape } return; } else { throw new ArgumentException("The shape type must be one of the polyline types to add a LineString geometry."); } } #endregion #region -------------------------- MULTI LINESTRING -------------------------------- if (geom.GetType() == typeof(MultiLineString)) { if (SpecifyShapeType == true) { mwShape.ShapeType = MapWinGIS.ShpfileType.SHP_POLYLINE; } MultiLineString MLS = geom as MultiLineString; if (mwShape.ShapeType == MapWinGIS.ShpfileType.SHP_POLYLINE || mwShape.ShapeType == MapWinGIS.ShpfileType.SHP_POLYLINEM || mwShape.ShapeType == MapWinGIS.ShpfileType.SHP_POLYLINEZ) { for (int iGeom = 0; iGeom < MLS.NumGeometries; iGeom++) { LineString LS = MLS.Geometries[iGeom] as LineString; AppendGeometryToShape(LS, ref mwShape); // prevents a lot of code duplication } return; } else { throw new ArgumentException("Cannot append a MultiLineString geometry to a " + mwShape.ShapeType.ToString() + " shape."); } } #endregion #region -------------------------- POLYGON ----------------------------------------- if (geom.GetType() == typeof(Polygon)) { Polygon newPolygon = geom as Polygon; if (SpecifyShapeType == true) { mwShape.ShapeType = MapWinGIS.ShpfileType.SHP_POLYGON; } if (mwShape.ShapeType == MapWinGIS.ShpfileType.SHP_POLYGON || mwShape.ShapeType == MapWinGIS.ShpfileType.SHP_POLYGONM || mwShape.ShapeType == MapWinGIS.ShpfileType.SHP_POLYGONZ) { mwShape.InsertPart(rfPt, ref rfPrt); rfPrt++; ILinearRing Shell = newPolygon.Shell; for (int iPoint = 0; iPoint < Shell.NumPoints; iPoint++) { ICoordinate Coord = Shell.Coordinates[iPoint]; mwPoint = new MapWinGIS.Point(); mwPoint.x = Coord.X; mwPoint.y = Coord.Y; mwShape.InsertPoint(mwPoint, ref rfPt); rfPt++; } // The same hole may appear multiple times in overlapping polygons. // Create a list of holes in order to test clockwise. if (newPolygon.NumInteriorRings > 0) { List <ILinearRing> UniqueHoles = new List <ILinearRing>(); List <ILinearRing> Holes = GetHoles(mwShape); //holes in the existing shape for (int iHole = 0; iHole < newPolygon.NumInteriorRings; iHole++) { if (Holes.Count > 0) { for (int jHole = 0; jHole < Holes.Count; jHole++) { if (newPolygon.Holes[iHole] == Holes[jHole]) { continue; } // if we get here, the new hole is unique and should be added UniqueHoles.Add(newPolygon.Holes[iHole]); // Also add it to the list to compare against other future holes Holes.Add(newPolygon.Holes[iHole]); // Holes.Count is re-evaluated each time so this should be ok } } //else //{ // //make sure holes are added to a shape with no holes // UniqueHoles.Add(newPolygon.Holes[iHole]); // Holes.Add(newPolygon.Holes[iHole]); //} } for (int iHole = 0; iHole < UniqueHoles.Count; iHole++) { mwShape.InsertPart(rfPt, ref rfPrt); rfPrt++; ICoordinate[] Hole; if (IsClockwise(UniqueHoles[iHole].Coordinates)) { // Holes should be counter clockwise Hole = UniqueHoles[iHole].Reverse().Coordinates; } else { Hole = UniqueHoles[iHole].Coordinates; } int Count = Hole.GetUpperBound(0) + 1; for (int iPoint = 0; iPoint < Count; iPoint++) { ICoordinate Coord = Hole[iPoint]; mwPoint = new MapWinGIS.Point(); mwPoint.x = Coord.X; mwPoint.y = Coord.Y; mwShape.InsertPoint(mwPoint, ref rfPt); rfPt++; } } } } } #endregion #region -------------------------- MULTI POLYGON------------------------------------ // The reason not to just Call Add Polygon recursively with this is that we only // want to test for unique holes once. Doing so each and every time we add a polygon // would be a major inefficiency, plus the overhead from converting back and forth // to a shape object. if (geom.GetType() == typeof(MultiPolygon)) { MultiPolygon MPG = geom as MultiPolygon; if (SpecifyShapeType == true) { mwShape.ShapeType = MapWinGIS.ShpfileType.SHP_POLYGON; } if (mwShape.ShapeType == MapWinGIS.ShpfileType.SHP_POLYGON || mwShape.ShapeType == MapWinGIS.ShpfileType.SHP_POLYGONM || mwShape.ShapeType == MapWinGIS.ShpfileType.SHP_POLYGONZ) { // By doing this one time up here, we prevent a lot of duplication List <ILinearRing> Holes = Holes = GetHoles(mwShape); for (int iPolygon = 0; iPolygon < MPG.NumGeometries; iPolygon++) { Polygon newPolygon = MPG.Geometries[iPolygon] as Polygon; mwShape.InsertPart(rfPt, ref rfPrt); rfPrt++; ILinearRing Shell = newPolygon.Shell; for (int iPoint = 0; iPoint < Shell.NumPoints; iPoint++) { ICoordinate Coord = Shell.Coordinates[iPoint]; mwPoint = new MapWinGIS.Point(); mwPoint.x = Coord.X; mwPoint.y = Coord.Y; mwShape.InsertPoint(mwPoint, ref rfPt); rfPt++; } // The same hole may appear multiple times in overlapping polygons. // Create a list of holes in order to test clockwise. if (newPolygon.NumInteriorRings > 0) { List <ILinearRing> UniqueHoles = new List <ILinearRing>(); for (int iHole = 0; iHole < newPolygon.NumInteriorRings; iHole++) { for (int jHole = 0; jHole < Holes.Count; jHole++) { if (newPolygon.Holes[iHole] == Holes[jHole]) { continue; } // if we get here, the new hole is unique and should be added UniqueHoles.Add(newPolygon.Holes[iHole]); // Also add it to the list to compare against other future holes Holes.Add(newPolygon.Holes[iHole]); // Holes.Count is re-evaluated each time so this should be ok } } for (int iHole = 0; iHole < UniqueHoles.Count; iHole++) { mwShape.InsertPart(rfPt, ref rfPrt); rfPrt++; ICoordinate[] Hole; if (IsClockwise(UniqueHoles[iHole].Coordinates)) { // Holes should be counter clockwise Hole = UniqueHoles[iHole].Reverse().Coordinates; } else { Hole = UniqueHoles[iHole].Coordinates; } int Count = Hole.GetUpperBound(0) + 1; for (int iPoint = 0; iPoint < Count; iPoint++) { ICoordinate Coord = Hole[iPoint]; mwPoint = new MapWinGIS.Point(); mwPoint.x = Coord.X; mwPoint.y = Coord.Y; mwShape.InsertPoint(mwPoint, ref rfPt); rfPt++; } } } } } } #endregion }
/// <summary> /// Reads the JSON representation of the object. /// </summary> /// <param name="reader">The <see cref="T:Newtonsoft.Json.JsonReader" /> to read from.</param> /// <param name="objectType">Type of the object.</param> /// <param name="existingValue">The existing existingValue of object being read.</param> /// <param name="serializer">The calling serializer.</param> /// <returns> /// Deserialized object. /// </returns> public override object ReadJson( JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { JToken token = JToken.Load(reader); if (token.Type == JTokenType.Null) { return(null); } if (token.Type != JTokenType.Object) { throw new JsonSerializationException(RMResources.SpatialInvalidGeometryType); } JToken typeToken = token["type"]; if (typeToken.Type != JTokenType.String) { throw new JsonSerializationException(RMResources.SpatialInvalidGeometryType); } Geometry result; switch (typeToken.Value <string>()) { case "Point": result = new Point(); break; case "MultiPoint": result = new MultiPoint(); break; case "LineString": result = new LineString(); break; case "MultiLineString": result = new MultiLineString(); break; case "Polygon": result = new Polygon(); break; case "MultiPolygon": result = new MultiPolygon(); break; case "GeometryCollection": result = new GeometryCollection(); break; default: throw new JsonSerializationException(RMResources.SpatialInvalidGeometryType); } serializer.Populate(token.CreateReader(), result); return(result); }
//private void getPointPointOverlay(PointD p1, PointD p2, OverlayType operation, ICollection<IGeometry> result) //{ // bool isEqual = p1.Equals(p2); // switch (operation) // { // case OverlayType.Intersection: // if (isEqual) // result.Add((IGeometry)p1.Clone()); // break; // case OverlayType.Union: // result.Add((IGeometry)p1.Clone()); // if (!isEqual) // result.Add((IGeometry)p2.Clone()); // break; // case OverlayType.Difference: // if (!isEqual) // result.Add((IGeometry)p1.Clone()); // break; // case OverlayType.SymmetricDifference: // if (!isEqual) // { // result.Add((IGeometry)p1.Clone()); // result.Add((IGeometry)p2.Clone()); // } // break; // } //} private void getPointPointOverlay(MultiPoint mp1, MultiPoint mp2, OverlayType operation, ICollection<IGeometry> result) { PlanarGraph graph = PlanarGraph.Build(mp1, mp2); switch (operation) { case OverlayType.Intersection: foreach (PlanarGraphNode node in graph.Nodes) if (node.Label.UsedByObject1 && node.Label.UsedByObject2) result.Add(new PointD(node.Point)); break; case OverlayType.Union: foreach (PlanarGraphNode node in graph.Nodes) result.Add(new PointD(node.Point)); break; case OverlayType.Difference: foreach (PlanarGraphNode node in graph.Nodes) if (node.Label.UsedByObject1 && !node.Label.UsedByObject2) result.Add(new PointD(node.Point)); break; case OverlayType.SymmetricDifference: foreach (PlanarGraphNode node in graph.Nodes) if (node.Label.UsedByObject1 ^ node.Label.UsedByObject2) result.Add(new PointD(node.Point)); break; } }
/// <summary> /// Reads and parses the geometry with ID 'oid' from the ShapeFile /// </summary> /// <remarks><see cref="FilterDelegate">Filtering</see> is not applied to this method</remarks> /// <param name="oid">Object ID</param> /// <returns>geometry</returns> // ReSharper disable once CyclomaticComplexity // Fix when changes need to be made here private Geometry ReadGeometry(uint oid) { _brShapeFile.BaseStream.Seek(GetShapeIndex(oid) + 8, 0); //Skip record number and content length var type = (ShapeType)_brShapeFile.ReadInt32(); //Shape type if (type == ShapeType.Null) { return(null); } if (_shapeType == ShapeType.Point || _shapeType == ShapeType.PointM || _shapeType == ShapeType.PointZ) { return(new Point(_brShapeFile.ReadDouble(), _brShapeFile.ReadDouble())); } if (_shapeType == ShapeType.Multipoint || _shapeType == ShapeType.MultiPointM || _shapeType == ShapeType.MultiPointZ) { _brShapeFile.BaseStream.Seek(32 + _brShapeFile.BaseStream.Position, 0); //skip min/max box var feature = new MultiPoint(); int nPoints = _brShapeFile.ReadInt32(); // get the number of points if (nPoints == 0) { return(null); } for (int i = 0; i < nPoints; i++) { feature.Points.Add(new Point(_brShapeFile.ReadDouble(), _brShapeFile.ReadDouble())); } return(feature); } if (_shapeType == ShapeType.PolyLine || _shapeType == ShapeType.Polygon || _shapeType == ShapeType.PolyLineM || _shapeType == ShapeType.PolygonM || _shapeType == ShapeType.PolyLineZ || _shapeType == ShapeType.PolygonZ) { _brShapeFile.BaseStream.Seek(32 + _brShapeFile.BaseStream.Position, 0); //skip min/max box int nParts = _brShapeFile.ReadInt32(); // get number of parts (segments) if (nParts == 0) { return(null); } int nPoints = _brShapeFile.ReadInt32(); // get number of points var segments = new int[nParts + 1]; //Read in the segment indexes for (int b = 0; b < nParts; b++) { segments[b] = _brShapeFile.ReadInt32(); } //add end point segments[nParts] = nPoints; if ((int)_shapeType % 10 == 3) { var mline = new MultiLineString(); for (int lineId = 0; lineId < nParts; lineId++) { var line = new LineString(); for (int i = segments[lineId]; i < segments[lineId + 1]; i++) { line.Vertices.Add(new Point(_brShapeFile.ReadDouble(), _brShapeFile.ReadDouble())); } mline.LineStrings.Add(line); } if (mline.LineStrings.Count == 1) { return(mline[0]); } return(mline); } else //(_ShapeType == ShapeType.Polygon etc...) { //First read all the rings var rings = new List <LinearRing>(); for (int ringId = 0; ringId < nParts; ringId++) { var ring = new LinearRing(); for (int i = segments[ringId]; i < segments[ringId + 1]; i++) { ring.Vertices.Add(new Point(_brShapeFile.ReadDouble(), _brShapeFile.ReadDouble())); } rings.Add(ring); } var isCounterClockWise = new bool[rings.Count]; int polygonCount = 0; for (int i = 0; i < rings.Count; i++) { isCounterClockWise[i] = rings[i].IsCCW(); if (!isCounterClockWise[i]) { polygonCount++; } } if (polygonCount == 1) //We only have one polygon { var poly = new Polygon { ExteriorRing = rings[0] }; if (rings.Count > 1) { for (int i = 1; i < rings.Count; i++) { poly.InteriorRings.Add(rings[i]); } } return(poly); } else { var mpoly = new MultiPolygon(); var poly = new Polygon { ExteriorRing = rings[0] }; for (var i = 1; i < rings.Count; i++) { if (!isCounterClockWise[i]) { mpoly.Polygons.Add(poly); poly = new Polygon(rings[i]); } else { poly.InteriorRings.Add(rings[i]); } } mpoly.Polygons.Add(poly); return(mpoly); } } } throw (new ApplicationException("Shapefile type " + _shapeType.ToString() + " not supported")); }
private void getPointPolygonOverlay(MultiPoint mp, Polygon polygon, OverlayType operation, GeometryCollection result, bool performSnapping, bool inverseArgs) { try { _geometry1 = mp; _geometry2 = polygon; bool isValid = true; try { init(performSnapping); PlanarGraph graph = PlanarGraph.Build(_geometry1, _geometry2); // duration test of the point inside the polygon to "collect" the original ground foreach (PlanarGraphEdge edge in graph.Edges) { edge.IsVisited = false; edge.Enabled = edge.Label.UsedByObject2; } Polygon pg = graph.BuildPolygon(inverseArgs, !inverseArgs); // classify edges and nodes foreach (PlanarGraphEdge edge in graph.Edges) { edge.IsVisited = false; switch (operation) { case OverlayType.Intersection: edge.Enabled = false; break; case OverlayType.Union: edge.Enabled = edge.Label.UsedByObject2; break; case OverlayType.Difference: edge.Enabled = inverseArgs ? edge.Label.UsedByObject2 : false; break; case OverlayType.SymmetricDifference: edge.Enabled = edge.Label.UsedByObject2; break; } } foreach (PlanarGraphNode node in graph.Nodes) { bool hasEnabledEdges = false; foreach (PlanarGraphEdge edge in node.IncidentEdges) if (edge.Enabled) { hasEnabledEdges = true; break; } if (hasEnabledEdges) node.Enabled = false; else { switch (operation) { case OverlayType.Intersection: node.Enabled = (pg.ContainsPoint(node.Point) && !node.Label.UsedByObject2) || (node.Label.UsedByObject2 && node.Label.UsedByObject1); break; case OverlayType.Union: node.Enabled = !pg.ContainsPoint(node.Point) && !node.Label.UsedByObject2; break; case OverlayType.Difference: node.Enabled = inverseArgs ? false : !pg.ContainsPoint(node.Point) && !node.Label.UsedByObject2; break; case OverlayType.SymmetricDifference: node.Enabled = !pg.ContainsPoint(node.Point) && !node.Label.UsedByObject2; break; } } } // build results: // point List<PointD> points = graph.BuildPoints(); foreach (PointD p in points) result.Add(p); // The landfill has been constructed to assess the position of the point. // But it must be added to the result only in the case of the calculation of association, // symmetric difference and the difference, which is a decrease. if (operation == OverlayType.Union || operation == OverlayType.SymmetricDifference || (operation == OverlayType.Difference && inverseArgs)) { if (pg.CoordinateCount > 0) result.Add(pg); } for (int i = 0; i < result.Count; i++) { IGeometry g = translateGeometry(result[i], _translationCenter.X, _translationCenter.Y); if (g is PointD) result[i] = g; } } catch (TopologyException) { if (!performSnapping) isValid = false; else throw new InvalidOperationException("Unable to complete operation correctly with this value of tolerance (PlanimertyAlgorithms.Tolerance)"); } if (isValid) return; else { // overlay has not been calculated. // it may be possible to calculate the overlay aligned to the grid getPointPolygonOverlay(mp, polygon, operation, result, true, inverseArgs); return; } } finally { _geometry1 = null; _geometry2 = null; } }
async ValueTask <GeoJSONObject> ReadGeometryCore(NpgsqlReadBuffer buf, bool async, BoundingBoxBuilder?boundingBox) { await buf.Ensure(SizeOfHeader, async); var littleEndian = buf.ReadByte() > 0; var type = (EwkbGeometryType)buf.ReadUInt32(littleEndian); GeoJSONObject geometry; NamedCRS? crs = null; if (HasSrid(type)) { await buf.Ensure(4, async); crs = GetCrs(buf.ReadInt32(littleEndian)); } switch (type & EwkbGeometryType.BaseType) { case EwkbGeometryType.Point: { await buf.Ensure(SizeOfPoint(type), async); var position = ReadPosition(buf, type, littleEndian); boundingBox?.Accumulate(position); geometry = new Point(position); break; } case EwkbGeometryType.LineString: { await buf.Ensure(SizeOfLength, async); var coordinates = new Position[buf.ReadInt32(littleEndian)]; for (var i = 0; i < coordinates.Length; ++i) { await buf.Ensure(SizeOfPoint(type), async); var position = ReadPosition(buf, type, littleEndian); boundingBox?.Accumulate(position); coordinates[i] = position; } geometry = new LineString(coordinates); break; } case EwkbGeometryType.Polygon: { await buf.Ensure(SizeOfLength, async); var lines = new LineString[buf.ReadInt32(littleEndian)]; for (var i = 0; i < lines.Length; ++i) { var coordinates = new Position[buf.ReadInt32(littleEndian)]; for (var j = 0; j < coordinates.Length; ++j) { await buf.Ensure(SizeOfPoint(type), async); var position = ReadPosition(buf, type, littleEndian); boundingBox?.Accumulate(position); coordinates[j] = position; } lines[i] = new LineString(coordinates); } geometry = new Polygon(lines); break; } case EwkbGeometryType.MultiPoint: { await buf.Ensure(SizeOfLength, async); var points = new Point[buf.ReadInt32(littleEndian)]; for (var i = 0; i < points.Length; ++i) { await buf.Ensure(SizeOfHeader + SizeOfPoint(type), async); await buf.Skip(SizeOfHeader, async); var position = ReadPosition(buf, type, littleEndian); boundingBox?.Accumulate(position); points[i] = new Point(position); } geometry = new MultiPoint(points); break; } case EwkbGeometryType.MultiLineString: { await buf.Ensure(SizeOfLength, async); var lines = new LineString[buf.ReadInt32(littleEndian)]; for (var i = 0; i < lines.Length; ++i) { await buf.Ensure(SizeOfHeaderWithLength, async); await buf.Skip(SizeOfHeader, async); var coordinates = new Position[buf.ReadInt32(littleEndian)]; for (var j = 0; j < coordinates.Length; ++j) { await buf.Ensure(SizeOfPoint(type), async); var position = ReadPosition(buf, type, littleEndian); boundingBox?.Accumulate(position); coordinates[j] = position; } lines[i] = new LineString(coordinates); } geometry = new MultiLineString(lines); break; } case EwkbGeometryType.MultiPolygon: { await buf.Ensure(SizeOfLength, async); var polygons = new Polygon[buf.ReadInt32(littleEndian)]; for (var i = 0; i < polygons.Length; ++i) { await buf.Ensure(SizeOfHeaderWithLength, async); await buf.Skip(SizeOfHeader, async); var lines = new LineString[buf.ReadInt32(littleEndian)]; for (var j = 0; j < lines.Length; ++j) { var coordinates = new Position[buf.ReadInt32(littleEndian)]; for (var k = 0; k < coordinates.Length; ++k) { await buf.Ensure(SizeOfPoint(type), async); var position = ReadPosition(buf, type, littleEndian); boundingBox?.Accumulate(position); coordinates[k] = position; } lines[j] = new LineString(coordinates); } polygons[i] = new Polygon(lines); } geometry = new MultiPolygon(polygons); break; } case EwkbGeometryType.GeometryCollection: { await buf.Ensure(SizeOfLength, async); var elements = new IGeometryObject[buf.ReadInt32(littleEndian)]; for (var i = 0; i < elements.Length; ++i) { elements[i] = (IGeometryObject) await ReadGeometryCore(buf, async, boundingBox); } geometry = new GeometryCollection(elements); break; } default: throw UnknownPostGisType(); } geometry.CRS = crs; return(geometry); }
public static MultiPoint ReadMultiPoint( JsonArray points ) { points.RequireArgument<JsonArray>( "points" ).NotNull<JsonArray>(); MultiPoint multiPoint = new MultiPoint(); foreach( JsonValue entry in points ) { JsonArray coordinates = entry as JsonArray; multiPoint.Points.Add(ReadPoint(coordinates)); } return multiPoint; }
public void GetHashCodeShoulBeComputed() { var multiPoint = new MultiPoint(new[] { new Point(1.0, 2.0), new Point(3.0, 4.0) }); Assert.AreEqual(2024009049, multiPoint.GetHashCode()); }