public void Multils() { Random rnd = new Random(); LineString[] ls = new LineString[40]; GeoAPI.Geometries.ILineString[] lscheck = new GeoAPI.Geometries.ILineString[40]; GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory gf = new GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory(); for (int ii = 0; ii < 40; ii++) { Coordinate[] coord = new Coordinate[36]; GeoAPI.Geometries.ICoordinate[] coordcheck = new GeoAPI.Geometries.ICoordinate[36]; for (int i = 0; i < 36; i++) { coord[i] = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90); double x = coord[i].X; double y = coord[i].Y; GisSharpBlog.NetTopologySuite.Geometries.Coordinate c = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(x, y); coordcheck[i] = c; } ls[ii] = new LineString(coord); lscheck[ii] = gf.CreateLineString(coordcheck); } MultiLineString mls = new MultiLineString(ls); GeoAPI.Geometries.IMultiLineString mlscheck = gf.CreateMultiLineString(lscheck); for (int ii = 0; ii < mls.Coordinates.Count; ii++) { Assert.AreEqual(mls.Coordinates[ii].X, mlscheck.Coordinates[ii].X); Assert.AreEqual(mls.Coordinates[ii].Y, mlscheck.Coordinates[ii].Y); } Assert.AreEqual(mls.NumGeometries, mlscheck.NumGeometries); }
public void PolygonArea() { Coordinate[] coords = new Coordinate[20]; Random rnd = new Random(); Coordinate center = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90); GeoAPI.Geometries.ICoordinate[] coordscheck = new GeoAPI.Geometries.ICoordinate[20]; for (int i = 0; i < 19; i++) { coords[i] = new Coordinate(center.X + Math.Cos((i * 10) * Math.PI / 10), center.Y + (i * 10) * Math.PI / 10); double x = coords[i].X; double y = coords[i].Y; GisSharpBlog.NetTopologySuite.Geometries.Coordinate c = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(x, y); coordscheck[i] = c; } coordscheck[19] = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(coordscheck[0].X, coordscheck[0].Y); coords[19] = new Coordinate(coords[0].X, coords[0].Y); GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory gf = new GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory(); GeoAPI.Geometries.ILinearRing ring = gf.CreateLinearRing(coordscheck); GeoAPI.Geometries.IPolygon polygonCheck = gf.CreatePolygon(ring, null); Polygon pg = new Polygon(coords); double areaCheck = polygonCheck.Area; double area = pg.Area; Assert.AreEqual(area, areaCheck); }
public void PolygonEnvelopeMaxMin() { Coordinate[] coords = new Coordinate[20]; Random rnd = new Random(); Coordinate center = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90); GeoAPI.Geometries.ICoordinate[] coordscheck = new GeoAPI.Geometries.ICoordinate[20]; for (int i = 0; i < 19; i++) { coords[i] = new Coordinate(center.X + Math.Cos((i * 10) * Math.PI / 10), center.Y + (i * 10) * Math.PI / 10); double x = coords[i].X; double y = coords[i].Y; GisSharpBlog.NetTopologySuite.Geometries.Coordinate c = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(x, y); coordscheck[i] = c; } coordscheck[19] = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(coords[0].X, coords[0].Y); coords[19] = new Coordinate(coords[0].X, coords[0].Y); GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory gf = new GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory(); GeoAPI.Geometries.ILinearRing ring = gf.CreateLinearRing(coordscheck); GeoAPI.Geometries.IPolygon pgcheck = gf.CreatePolygon(ring, null); Polygon pg = new Polygon(coords); AssertExt.AreEqual15(pg.Envelope.Maximum.X, pgcheck.EnvelopeInternal.MaxX); AssertExt.AreEqual15(pg.Envelope.Maximum.Y, pgcheck.EnvelopeInternal.MaxY); AssertExt.AreEqual15(pg.Envelope.Minimum.X, pgcheck.EnvelopeInternal.MinX); AssertExt.AreEqual15(pg.Envelope.Minimum.Y, pgcheck.EnvelopeInternal.MinY); }
public void Multipg() { Random rnd = new Random(); Polygon[] pg = new Polygon[50]; GeoAPI.Geometries.IPolygon[] pgcheck = new GeoAPI.Geometries.IPolygon[50]; GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory gf = new GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory(); for (int i = 0; i < 50; i++) { Coordinate center = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90); Coordinate[] coord = new Coordinate[36]; GeoAPI.Geometries.ICoordinate[] coordscheck = new GeoAPI.Geometries.ICoordinate[36]; for (int ii = 0; ii < 36; ii++) { coord[ii] = new Coordinate(center.X + Math.Cos((ii * 10) * Math.PI / 10), center.Y + (ii * 10) * Math.PI / 10); double x = coord[ii].X; double y = coord[ii].Y; GisSharpBlog.NetTopologySuite.Geometries.Coordinate c = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(x, y); coordscheck[ii] = c; } coord[35] = new Coordinate(coord[0].X, coord[0].Y); coordscheck[35] = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(coordscheck[0].X, coordscheck[0].Y); GeoAPI.Geometries.ILinearRing ring = gf.CreateLinearRing(coordscheck); pgcheck[i] = gf.CreatePolygon(ring, null); pg[i] = new Polygon(coord); } MultiPolygon mpg = new MultiPolygon(pg); GeoAPI.Geometries.IMultiPolygon mpgcheck = gf.CreateMultiPolygon(pgcheck); for (int ii = 0; ii < mpg.Coordinates.Count; ii++) { Assert.AreEqual(mpg.Coordinates[ii].X, mpgcheck.Coordinates[ii].X); Assert.AreEqual(mpg.Coordinates[ii].Y, mpgcheck.Coordinates[ii].Y); } }
public void MlsLength() { Random rnd = new Random(); LineString[] ls = new LineString[40]; GeoAPI.Geometries.ILineString[] lscheck = new GeoAPI.Geometries.ILineString[40]; GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory gf = new GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory(); for (int ii = 0; ii < 40; ii++) { Coordinate[] coord = new Coordinate[36]; GeoAPI.Geometries.ICoordinate[] coordcheck = new GeoAPI.Geometries.ICoordinate[36]; for (int i = 0; i < 36; i++) { coord[i] = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90); double x = coord[i].X; double y = coord[i].Y; GisSharpBlog.NetTopologySuite.Geometries.Coordinate c = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(x, y); coordcheck[i] = c; } ls[ii] = new LineString(coord); lscheck[ii] = gf.CreateLineString(coordcheck); } MultiLineString mls = new MultiLineString(ls); GeoAPI.Geometries.IMultiLineString mlscheck = gf.CreateMultiLineString(lscheck); Assert.AreEqual(mls.Length, mlscheck.Length); }
public void Overlaps() { Random rnd = new Random(); Polygon[] pg = new Polygon[50]; GeoAPI.Geometries.IPolygon[] pgcheck = new GeoAPI.Geometries.IPolygon[50]; GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory gf = new GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory(); Coordinate center = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90); for (int i = 0; i < 50; i++) { Coordinate[] coord = new Coordinate[36]; GeoAPI.Geometries.ICoordinate[] coordscheck = new GeoAPI.Geometries.ICoordinate[36]; for (int ii = 0; ii < 36; ii++) { coord[ii] = new Coordinate(center.X + Math.Cos((ii * 10) * Math.PI / 10), center.Y + (ii * 10) * Math.PI / 10); double x = coord[ii].X; double y = coord[ii].Y; GisSharpBlog.NetTopologySuite.Geometries.Coordinate c = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(x, y); coordscheck[ii] = c; } coord[35] = new Coordinate(coord[0].X, coord[0].Y); coordscheck[35] = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(coordscheck[0].X, coordscheck[0].Y); GeoAPI.Geometries.ILinearRing ring = gf.CreateLinearRing(coordscheck); pgcheck[i] = gf.CreatePolygon(ring, null); pg[i] = new Polygon(coord); } for (int t = 0; t < 49; t++) { bool g = pg[t].Overlaps(pg[t + 1]); bool gcheck = pgcheck[t].Overlaps(pgcheck[t + 1]); Assert.AreEqual(g, gcheck); } }
public void MpsBufferArea() { Coordinate[] c = new Coordinate[36]; Random rnd = new Random(); GeoAPI.Geometries.ICoordinate[] ccheck = new GeoAPI.Geometries.ICoordinate[36]; GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory gf = new GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory(); for (int i = 0; i < 36; i++) { c[i] = new Coordinate((rnd.NextDouble() + 360) - 180, (rnd.NextDouble() * 180) - 90); double x = c[i].X; double y = c[i].Y; GisSharpBlog.NetTopologySuite.Geometries.Coordinate ctemp = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(x, y); ccheck[i] = ctemp; } GeoAPI.Geometries.IMultiPoint mpsCheck = gf.CreateMultiPoint(ccheck); MultiPoint mps = new MultiPoint(c); double area = mps.Buffer(500).Area; double areacheck = mpsCheck.Buffer(500).Area; if (Math.Abs(area - areacheck) > 0.000000001) { Assert.AreEqual(mps.Buffer(500).Area, mpsCheck.Buffer(500).Area); } }
public void PolygonHoles() { Coordinate[] coords = new Coordinate[20]; Random rnd = new Random(); Coordinate center = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90); // Shell Coordinates GeoAPI.Geometries.ICoordinate[] coordscheck = new GeoAPI.Geometries.ICoordinate[20]; for (int i = 0; i < 19; i++) { double x = center.X + Math.Cos((i * 10) * Math.PI / 10); double y = center.Y + (i * 10) * Math.PI / 10; coords[i] = new Coordinate(x, y); coordscheck[i] = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(x, y); } coordscheck[19] = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(coords[0].X, coords[0].Y); coords[19] = new Coordinate(coords[0].X, coords[0].Y); // Shell Rings LinearRing ring = new LinearRing(coords); GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory gf = new GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory(); GeoAPI.Geometries.ILinearRing ringCheck = gf.CreateLinearRing(coordscheck); // Hole Coordinates GeoAPI.Geometries.ICoordinate[] coordsholecheck = new GeoAPI.Geometries.ICoordinate[20]; Coordinate[] coordshole = new Coordinate[20]; for (int i = 0; i < 20; i++) { double x = center.X + Math.Cos((i * 10) * Math.PI / 20); double y = center.Y + (i * 10) * Math.PI / 20; coordshole[i] = new Coordinate(x, y); coordsholecheck[i] = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(x, y); } coordshole[19] = new Coordinate(coordshole[0].X, coordshole[0].Y); coordsholecheck[19] = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(coordshole[0].X, coordshole[0].Y); // Hole LinearRing Arrays LinearRing hole = new LinearRing(coordshole); ILinearRing[] holes = new ILinearRing[1]; GeoAPI.Geometries.ILinearRing holeCheck = gf.CreateLinearRing(coordsholecheck); GeoAPI.Geometries.ILinearRing[] holescheck = new GeoAPI.Geometries.ILinearRing[1]; holes[0] = hole; holescheck[0] = holeCheck; Polygon pg = new Polygon(ring, holes); GeoAPI.Geometries.IPolygon polygonCheck = gf.CreatePolygon(ringCheck, holescheck); double areaCheck = polygonCheck.Area; double area = pg.Area; Assert.AreEqual(area, areaCheck); }
public GeoAPI.Geometries.ICoordinate CrossProduct(GeoAPI.Geometries.ICoordinate u, GeoAPI.Geometries.ICoordinate v) { double a = u.Y * v.Z - u.Z * v.Y; double b = u.Z * v.X - u.X * v.Z; double c = u.X * v.Y - u.Y * v.X; GeoAPI.Geometries.ICoordinate coord = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(a, b, c); return(coord); }
internal static GisSharpBlog.NetTopologySuite.Geometries.LinearRing ToNTSLinearRing(SharpMap.Geometries.LinearRing linearRing, GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory factory) { GisSharpBlog.NetTopologySuite.Geometries.Coordinate[] coordinates = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate[linearRing.NumPoints]; int index = 0; foreach (SharpMap.Geometries.Point point in linearRing.Vertices) { coordinates[index++] = ToNTSCoordinate(point, factory); } return(factory.CreateLinearRing(coordinates) as GisSharpBlog.NetTopologySuite.Geometries.LinearRing); }
public override void OnMouseMove(ICoordinate worldPosition, MouseEventArgs e) { //base.OnMouseMove(e); if (Map != null) { bool isStartDrag = Map != null && e.Location != _dragStartPoint && !_dragging && (e.Button == MouseButtons.Left || e.Button == MouseButtons.Middle) && //Left of middle button can start drag !(MapControl.DrawPolygonTool.IsActive); //It should not be any of these tools if (isStartDrag) { _dragging = true; } if (_dragging) { //bool isPanOperation = true; //if (IsDrawPolygon) //{ // isPanOperation = true; //} //if (isPanOperation) //{ _dragEndPoint = ClipPoint(e.Location); if (_dragStartCoord != null) { GisSharpBlog.NetTopologySuite.Geometries.Coordinate newCoord = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(); newCoord.X = _dragStartCoord.X - Map.PixelSize * (_dragEndPoint.X - _dragStartPoint.X); newCoord.Y = _dragStartCoord.Y - Map.PixelSize * (_dragStartPoint.Y - _dragEndPoint.Y); Map.Center = newCoord; //if (MapCenterChanged != null) // MapCenterChanged(map.Center); MapControl.Invalidate(MapControl.ClientRectangle); } //} } else { _dragEndPoint = new Point(0, 0); if (pointArray != null) { pointArray[pointArray.Count - 1] = Map.ImageToWorld(ClipPoint(e.Location)); _rectangle = GenerateRectangle(_dragStartPoint, ClipPoint(e.Location)); MapControl.Invalidate(new Region(MapControl.ClientRectangle)); } } } }
public void EnvelopeCoordinate() { Random rnd = new Random(); Coordinate c = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90); Envelope ev = new Envelope(c); double x = c.X; double y = c.Y; GisSharpBlog.NetTopologySuite.Geometries.Coordinate ccheck = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(x, y); GisSharpBlog.NetTopologySuite.Geometries.Envelope evcheck = new GisSharpBlog.NetTopologySuite.Geometries.Envelope(ccheck); AssertExt.AreEqual15(ev.Maximum.Y, evcheck.MaxY); AssertExt.AreEqual15(ev.Maximum.X, evcheck.MaxX); AssertExt.AreEqual15(ev.Minimum.Y, evcheck.MinY); AssertExt.AreEqual15(ev.Minimum.X, evcheck.MinX); }
public void Buffer() { Random rnd = new Random(); Coordinate coords = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90); double x = coords.X; double y = coords.Y; GisSharpBlog.NetTopologySuite.Geometries.Coordinate c = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(x, y); //coordscheck[i] = c; Point p = new Point(coords); GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory gf = new GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory(); GeoAPI.Geometries.IPoint ps = gf.CreatePoint(c); double area = p.Buffer(500).Area; double areacheck = ps.Buffer(500).Area; Assert.AreEqual(area, areacheck); }
public void Center() { Random rnd = new Random(); Coordinate c1 = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90); Coordinate c2 = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90); Envelope ev = new Envelope(c1, c2); double x1 = c1.X; double y1 = c1.Y; double x2 = c2.X; double y2 = c2.Y; GisSharpBlog.NetTopologySuite.Geometries.Coordinate c1Check = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(x1, y1); GisSharpBlog.NetTopologySuite.Geometries.Coordinate c2Check = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(x2, y2); GisSharpBlog.NetTopologySuite.Geometries.Envelope evcheck = new GisSharpBlog.NetTopologySuite.Geometries.Envelope(c1Check, c2Check); Coordinate center = new Coordinate(ev.Center()); GisSharpBlog.NetTopologySuite.Geometries.Coordinate centercheck = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(evcheck.Centre); AssertExt.AreEqual15(center.X, centercheck.X); AssertExt.AreEqual15(center.Y, centercheck.Y); }
public void TwoCoordinates() { Random rnd = new Random(); Coordinate c1 = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90); Coordinate c2 = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90); Envelope ev = new Envelope(c1, c2); double x1 = c1.X; double y1 = c1.Y; double x2 = c2.X; double y2 = c2.Y; GisSharpBlog.NetTopologySuite.Geometries.Coordinate c1Check = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(x1, y1); GisSharpBlog.NetTopologySuite.Geometries.Coordinate c2Check = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(x2, y2); GisSharpBlog.NetTopologySuite.Geometries.Envelope evcheck = new GisSharpBlog.NetTopologySuite.Geometries.Envelope(c1Check, c2Check); AssertExt.AreEqual15(ev.Maximum.Y, evcheck.MaxY); AssertExt.AreEqual15(ev.Maximum.X, evcheck.MaxX); AssertExt.AreEqual15(ev.Minimum.Y, evcheck.MinY); AssertExt.AreEqual15(ev.Minimum.X, evcheck.MinX); }
public void LineStringEnvelopeHeightWidth() { Coordinate[] coords = new Coordinate[36]; Random rnd = new Random(); GeoAPI.Geometries.ICoordinate[] coordscheck = new GeoAPI.Geometries.ICoordinate[36]; for (int i = 0; i < 36; i++) { coords[i] = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90); double x = coords[i].X; double y = coords[i].Y; GisSharpBlog.NetTopologySuite.Geometries.Coordinate c = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(x, y); coordscheck[i] = c; } GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory gf = new GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory(); GeoAPI.Geometries.ILineString lscheck = gf.CreateLineString(coordscheck); LineString ls = new LineString(coords); AssertExt.AreEqual15(ls.Envelope.Width, lscheck.EnvelopeInternal.Width); AssertExt.AreEqual15(ls.Envelope.Height, lscheck.EnvelopeInternal.Height); }
public void LineLength() { Coordinate[] coords = new Coordinate[36]; Random rnd = new Random(); GeoAPI.Geometries.ICoordinate[] coordscheck = new GeoAPI.Geometries.ICoordinate[36]; for (int i = 0; i < 36; i++) { coords[i] = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90); double x = coords[i].X; double y = coords[i].Y; GisSharpBlog.NetTopologySuite.Geometries.Coordinate c = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(x, y); coordscheck[i] = c; } GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory gf = new GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory(); GeoAPI.Geometries.ILineString lscheck = gf.CreateLineString(coordscheck); LineString ls = new LineString(coords); double length = ls.Length; double lengthcheck = lscheck.Length; Assert.AreEqual(length, lengthcheck); }
public void LineStringCoordiantesCount() { Coordinate[] coords = new Coordinate[36]; Random rnd = new Random(); GeoAPI.Geometries.ICoordinate[] coordscheck = new GeoAPI.Geometries.ICoordinate[36]; for (int i = 0; i < 36; i++) { coords[i] = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90); double x = coords[i].X; double y = coords[i].Y; GisSharpBlog.NetTopologySuite.Geometries.Coordinate c = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(x, y); coordscheck[i] = c; } GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory gf = new GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory(); GeoAPI.Geometries.ILineString lscheck = gf.CreateLineString(coordscheck); LineString ls = new LineString(coords); Assert.AreEqual(ls.Coordinates.Count, lscheck.Coordinates.Count()); }
public void Intersection() { Random rnd = new Random(); Polygon[] pg = new Polygon[50]; GeoAPI.Geometries.IPolygon[] pgcheck = new GeoAPI.Geometries.IPolygon[50]; GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory gf = new GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory(); Coordinate center = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90); for (int i = 0; i < 50; i++) { Coordinate[] coord = new Coordinate[36]; GeoAPI.Geometries.ICoordinate[] coordscheck = new GeoAPI.Geometries.ICoordinate[36]; for (int ii = 0; ii < 36; ii++) { coord[ii] = new Coordinate(center.X + Math.Cos((ii * 10) * Math.PI / 10), center.Y + (ii * 10) * Math.PI / 10); double x = coord[ii].X; double y = coord[ii].Y; GisSharpBlog.NetTopologySuite.Geometries.Coordinate c = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(x, y); coordscheck[ii] = c; } coord[35] = new Coordinate(coord[0].X, coord[0].Y); coordscheck[35] = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(coordscheck[0].X, coordscheck[0].Y); GeoAPI.Geometries.ILinearRing ring = gf.CreateLinearRing(coordscheck); pgcheck[i] = gf.CreatePolygon(ring, null); pg[i] = new Polygon(coord); } for (int t = 0; t < 49; t++) { IGeometry g = pg[t].Intersection(pg[t + 1]); GeoAPI.Geometries.IGeometry gcheck = pgcheck[t].Intersection(pgcheck[t + 1]); for (int j = 0; j < g.Coordinates.Count; j++) { Assert.AreEqual(g.Coordinates[j].X, gcheck.Coordinates[j].X); Assert.AreEqual(g.Coordinates[j].Y, gcheck.Coordinates[j].Y); } } }
public void MultiPs() { Coordinate[] c = new Coordinate[36]; Random rnd = new Random(); GeoAPI.Geometries.ICoordinate[] ccheck = new GeoAPI.Geometries.ICoordinate[36]; GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory gf = new GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory(); for (int i = 0; i < 36; i++) { c[i] = new Coordinate((rnd.NextDouble() + 360) - 180, (rnd.NextDouble() * 180) - 90); double x = c[i].X; double y = c[i].Y; GisSharpBlog.NetTopologySuite.Geometries.Coordinate ctemp = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(x, y); ccheck[i] = ctemp; } GeoAPI.Geometries.IMultiPoint mpsCheck = gf.CreateMultiPoint(ccheck); MultiPoint mps = new MultiPoint(c); for (int 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); } }
internal static SharpMap.Geometries.Point ToSharpMapPoint(GisSharpBlog.NetTopologySuite.Geometries.Coordinate coordinate) { return(new SharpMap.Geometries.Point(coordinate.X, coordinate.Y)); }
public void EnvelopeHeight() { Random rnd = new Random(); Polygon[] pg = new Polygon[50]; GeoAPI.Geometries.IPolygon[] pgcheck = new GeoAPI.Geometries.IPolygon[50]; GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory gf = new GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory(); for (int i = 0; i < 50; i++) { Coordinate center = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90); Coordinate[] coord = new Coordinate[36]; GeoAPI.Geometries.ICoordinate[] coordscheck = new GeoAPI.Geometries.ICoordinate[36]; for (int ii = 0; ii < 36; ii++) { coord[ii] = new Coordinate(center.X + Math.Cos((ii * 10) * Math.PI / 10), center.Y + (ii * 10) * Math.PI / 10); double x = coord[ii].X; double y = coord[ii].Y; GisSharpBlog.NetTopologySuite.Geometries.Coordinate c = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(x, y); coordscheck[ii] = c; } coord[35] = new Coordinate(coord[0].X, coord[0].Y); coordscheck[35] = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(coordscheck[0].X, coordscheck[0].Y); GeoAPI.Geometries.ILinearRing ring = gf.CreateLinearRing(coordscheck); pgcheck[i] = gf.CreatePolygon(ring, null); pg[i] = new Polygon(coord); } MultiPolygon mpg = new MultiPolygon(pg); GeoAPI.Geometries.IMultiPolygon mpgcheck = gf.CreateMultiPolygon(pgcheck); Assert.AreEqual(mpg.Envelope.Height, mpgcheck.EnvelopeInternal.Height); }
internal static GisSharpBlog.NetTopologySuite.Geometries.LinearRing ToNTSLinearRing(SharpMap.Geometries.LinearRing linearRing, GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory factory) { GisSharpBlog.NetTopologySuite.Geometries.Coordinate[] coordinates = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate[linearRing.NumPoints]; int index = 0; foreach (SharpMap.Geometries.Point point in linearRing.Vertices) coordinates[index++] = ToNTSCoordinate(point, factory); return factory.CreateLinearRing(coordinates); }
public static Region DrawLineString(System.Drawing.Graphics g, SharpMap.Geometries.LineString line, System.Drawing.Pen pen, SharpMap.Map map) { if (line.Vertices.Count > 1) { System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath(); PointF[] points = line.TransformToImage(map); gp.AddLines(points); g.DrawPath(pen, gp); GisSharpBlog.NetTopologySuite.Geometries.Coordinate[] coords = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate[points.Length]; for (int i = 0; i < points.Length; i++) coords[i] = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(points[i].X, points[i].Y); GisSharpBlog.NetTopologySuite.Geometries.LineString ls = new GisSharpBlog.NetTopologySuite.Geometries.LineString(coords); GisSharpBlog.NetTopologySuite.Geometries.Coordinate[] linearRingPoints = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate[5]; linearRingPoints[0] = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(0, 0); linearRingPoints[1] = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(map.Size.Width, 0); linearRingPoints[2] = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(map.Size.Width, map.Size.Height); linearRingPoints[3] = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(0, map.Size.Height); linearRingPoints[4] = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(0, 0); GisSharpBlog.NetTopologySuite.Geometries.LinearRing ring = new GisSharpBlog.NetTopologySuite.Geometries.LinearRing(linearRingPoints); GeoAPI.Geometries.IGeometry geom = ls.Intersection(new GisSharpBlog.NetTopologySuite.Geometries.Polygon(ring)); System.Drawing.Drawing2D.GraphicsPath gp2 = new System.Drawing.Drawing2D.GraphicsPath(); Pen p2 = new Pen(Color.Black, pen.Width < 4 ? 4 : pen.Width); if (geom is GisSharpBlog.NetTopologySuite.Geometries.LineString) { GisSharpBlog.NetTopologySuite.Geometries.LineString lineString = geom as GisSharpBlog.NetTopologySuite.Geometries.LineString; System.Drawing.PointF[] v = new System.Drawing.PointF[lineString.Coordinates.Length]; for (int i = 0; i < lineString.Coordinates.Length; i++) v[i] = new PointF((float)lineString.Coordinates[i].X, (float)lineString.Coordinates[i].Y); gp2.AddLines(v); } if (geom is GisSharpBlog.NetTopologySuite.Geometries.GeometryCollection) { GisSharpBlog.NetTopologySuite.Geometries.GeometryCollection geomCollection = geom as GisSharpBlog.NetTopologySuite.Geometries.GeometryCollection; foreach (GisSharpBlog.NetTopologySuite.Geometries.Geometry cGeom in geomCollection) { if (cGeom is GisSharpBlog.NetTopologySuite.Geometries.LineString) { GisSharpBlog.NetTopologySuite.Geometries.LineString lineString = cGeom as GisSharpBlog.NetTopologySuite.Geometries.LineString; System.Drawing.PointF[] v = new System.Drawing.PointF[lineString.Coordinates.Length]; for (int i = 0; i < lineString.Coordinates.Length; i++) v[i] = new PointF((float)lineString.Coordinates[i].X, (float)lineString.Coordinates[i].Y); gp2.AddLines(v); } } } try { gp2.Widen(p2); System.Drawing.Region r = new System.Drawing.Region(gp2); return r; } catch (OutOfMemoryException) { return null; } } return null; }