public IGeometry CreateLine(Coordinate @base, double size, int nPts) { var gsf = new GeometricShapeFactory(); gsf.Centre = _origin; gsf.Size = size; gsf.NumPoints = nPts; var circle = gsf.CreateCircle(); // System.out.println(circle); return circle.Boundary; }
public IGeometry CreateCircle(int nPts) { var gsf = new GeometricShapeFactory(_geomFact); gsf.Centre = _origin; gsf.Size = _size; gsf.NumPoints = nPts; var circle = gsf.CreateCircle(); // var gRect = gsf.CreateRectangle(); // var g = gRect.ExteriorRing); return circle; }
static IGeometry CreateCircle(Coordinate origin, double size, int nPts) { GeometricShapeFactory gsf = new GeometricShapeFactory(); gsf.Centre = origin; gsf.Size = size; gsf.NumPoints = nPts; IGeometry circle = gsf.CreateCircle(); // Polygon gRect = gsf.createRectangle(); // Geometry g = gRect.getExteriorRing(); return circle; }
/** * Gets a JTS {@link Geometry} for the given {@link Shape}. Some shapes hold a * JTS geometry whereas new ones must be created for the rest. * @param shape Not null * @return Not null */ public IGeometry GetGeometryFrom(Shape shape) { if (shape is NtsGeometry) { return ((NtsGeometry)shape).GetGeom(); } if (shape is NtsPoint) { return ((NtsPoint)shape).GetGeom(); } var point = shape as Shapes.Point; if (point != null) { return geometryFactory.CreatePoint(new Coordinate(point.GetX(), point.GetY())); } var r = shape as Rectangle; if (r != null) { if (r.GetCrossesDateLine()) { var pair = new List<IGeometry>(2) { geometryFactory.ToGeometry(new Envelope( r.GetMinX(), GetWorldBounds().GetMaxX(), r.GetMinY(), r.GetMaxY())), geometryFactory.ToGeometry(new Envelope( GetWorldBounds().GetMinX(), r.GetMaxX(), r.GetMinY(), r.GetMaxY())) }; return geometryFactory.BuildGeometry(pair);//a MultiPolygon or MultiLineString } else { return geometryFactory.ToGeometry(new Envelope(r.GetMinX(), r.GetMaxX(), r.GetMinY(), r.GetMaxY())); } } var circle = shape as Circle; if (circle != null) { // TODO, this should maybe pick a bunch of points // and make a circle like: // http://docs.codehaus.org/display/GEOTDOC/01+How+to+Create+a+Geometry#01HowtoCreateaGeometry-CreatingaCircle // If this crosses the dateline, it could make two parts // is there an existing utility that does this? if (circle.GetBoundingBox().GetCrossesDateLine()) throw new ArgumentException("Doesn't support dateline cross yet: " + circle);//TODO var gsf = new GeometricShapeFactory(geometryFactory) { Size = circle.GetBoundingBox().GetWidth() / 2.0f, NumPoints = 4 * 25,//multiple of 4 is best Base = new Coordinate(circle.GetCenter().GetX(), circle.GetCenter().GetY()) }; return gsf.CreateCircle(); } throw new InvalidShapeException("can't make Geometry from: " + shape); }
static IGeometry CreateTestCircle(Coordinate origin, double size, int nPts) { GeometricShapeFactory gsf = new GeometricShapeFactory(); gsf.Centre = origin; gsf.Size = size; gsf.NumPoints = nPts; IGeometry circle = gsf.CreateCircle(); // System.out.println(circle); return circle; }
// returns closest feature to real-world coordinate // return null if no features within limit public Feature getClosest(Point p, double limit) { GeometricShapeFactory gsf = new GeometricShapeFactory(); gsf.Envelope = new Envelope(p.X - limit, p.X + limit, p.Y - limit, p.Y + limit); IGeometry circle = gsf.CreateCircle(); var candidates = getWithin(circle); double min = 0; Feature minf = null; foreach (var f in candidates) { double dist = f.Geometry.Distance(p); if (minf == null || dist < min) { minf = f; min = dist; } } return minf; }
static ILineString CreateTestLine(Coordinate basePt, double size, int nPts) { GeometricShapeFactory gsf = new GeometricShapeFactory(); gsf.Centre = basePt; gsf.Size = size; gsf.NumPoints = nPts; IGeometry circle = gsf.CreateCircle(); // System.out.println(circle); return (ILineString)circle.Boundary; }