/// <summary> /// Reads a stream and converts the shapefile record to an equilivent geometry object. /// </summary> /// <param name="file">The stream to read.</param> /// <param name="geometryFactory">The geometry factory to use when making the object.</param> /// <returns>The Geometry object that represents the shape file record.</returns> public override IGeometry Read(BigEndianBinaryReader file, IGeometryFactory geometryFactory) { int shapeTypeNum = file.ReadInt32(); type = (ShapeGeometryType)Enum.Parse(typeof(ShapeGeometryType), shapeTypeNum.ToString()); if (type == ShapeGeometryType.NullShape) { ICoordinate emptyCoordinate = null; return(geometryFactory.CreatePoint(emptyCoordinate)); } if (!(type == ShapeGeometryType.Point || type == ShapeGeometryType.PointM || type == ShapeGeometryType.PointZ || type == ShapeGeometryType.PointZM)) { throw new ShapefileException("Attempting to load a point as point."); } double x = file.ReadDouble(); double y = file.ReadDouble(); ICoordinate external = new Coordinate(x, y); geometryFactory.PrecisionModel.MakePrecise(external); IPoint point = geometryFactory.CreatePoint(external); GrabZMValue(file); return(point); }
/// <summary> /// Reads a stream and converts the shapefile record to an equilivent geometry object. /// </summary> /// <param name="file">The stream to read.</param> /// <param name="geometryFactory">The geometry factory to use when making the object.</param> /// <returns>The Geometry object that represents the shape file record.</returns> public override IGeometry Read(BigEndianBinaryReader file, IGeometryFactory geometryFactory) { int shapeTypeNum = file.ReadInt32(); type = (ShapeGeometryType) Enum.Parse(typeof (ShapeGeometryType), shapeTypeNum.ToString()); if (type == ShapeGeometryType.NullShape) { ICoordinate emptyCoordinate = null; return geometryFactory.CreatePoint(emptyCoordinate); } if (!(type == ShapeGeometryType.Point || type == ShapeGeometryType.PointM || type == ShapeGeometryType.PointZ || type == ShapeGeometryType.PointZM)) throw new ShapefileException("Attempting to load a point as point."); double x = file.ReadDouble(); double y = file.ReadDouble(); ICoordinate external = new Coordinate(x,y); geometryFactory.PrecisionModel.MakePrecise(external); IPoint point = geometryFactory.CreatePoint(external); if (HasZValue() || HasMValue()) { IDictionary<ShapeGeometryType, double> data = new Dictionary<ShapeGeometryType, double>(2); if (HasZValue()) GetZValue(file, data); if (HasMValue()) GetMValue(file, data); // point.UserData = data; } return point; }
private IGeometry ReadPoint() { ShapefileGeometryType type = (ShapefileGeometryType)_reader.ReadInt32(); if (type == ShapefileGeometryType.NullShape) { return(_gf.CreatePoint((Coordinate)null)); } if (type == ShapefileGeometryType.Point) { return(_gf.CreatePoint(new Coordinate( _reader.ReadDouble(), _reader.ReadDouble()))); } else if (type == ShapefileGeometryType.PointZ) { return(_gf.CreatePoint(new Coordinate( _reader.ReadDouble(), _reader.ReadDouble(), _reader.ReadDouble(), _reader.ReadDouble()))); } else { throw new Exception("Attempting to load a non-point as point."); } }
/// <summary> /// Reads a stream and converts the shapefile record to an equilivent geometry object. /// </summary> /// <param name="file">The stream to read.</param> /// <param name="totalRecordLength">Total length of the record we are about to read</param> /// <param name="factory">The geometry factory to use when making the object.</param> /// <returns>The Geometry object that represents the shape file record.</returns> public override IGeometry Read(BigEndianBinaryReader file, int totalRecordLength, IGeometryFactory factory) { int totalRead = 0; ShapeGeometryType type = (ShapeGeometryType)ReadInt32(file, totalRecordLength, ref totalRead); //type = (ShapeGeometryType) EnumUtility.Parse(typeof (ShapeGeometryType), shapeTypeNum.ToString()); if (type == ShapeGeometryType.NullShape) return factory.CreatePoint((Coordinate)null); if (type != ShapeType) throw new ShapefileException(string.Format("Encountered a '{0}' instead of a '{1}'", type, ShapeType)); CoordinateBuffer buffer = new CoordinateBuffer(1, NoDataBorderValue, true); IPrecisionModel precisionModel = factory.PrecisionModel; double x = precisionModel.MakePrecise(ReadDouble(file, totalRecordLength, ref totalRead)); double y = precisionModel.MakePrecise(ReadDouble(file, totalRecordLength, ref totalRead)); double? z = null, m = null; // Trond Benum: Let's read optional Z and M values if (HasZValue() && totalRead < totalRecordLength) z = ReadDouble(file, totalRecordLength, ref totalRead); if ((HasMValue() || HasZValue()) && (totalRead < totalRecordLength)) m = ReadDouble(file, totalRecordLength, ref totalRead); buffer.AddCoordinate(x, y, z, m); return factory.CreatePoint(buffer.ToSequence(factory.CoordinateSequenceFactory)); }
/// <summary> /// Reads a stream and converts the shapefile record to an equilivent geometry object. /// </summary> /// <param name="file">The stream to read.</param> /// <param name="totalRecordLength">Total length of the record we are about to read</param> /// <param name="factory">The geometry factory to use when making the object.</param> /// <returns>The Geometry object that represents the shape file record.</returns> public override IGeometry Read(BigEndianBinaryReader file, int totalRecordLength, IGeometryFactory factory) { int totalRead = 0; ShapeGeometryType type = (ShapeGeometryType)ReadInt32(file, totalRecordLength, ref totalRead); //type = (ShapeGeometryType) EnumUtility.Parse(typeof (ShapeGeometryType), shapeTypeNum.ToString()); if (type == ShapeGeometryType.NullShape) return factory.CreatePoint((Coordinate)null); if (type != ShapeType) throw new ShapefileException(string.Format("Encountered a '{0}' instead of a '{1}'", type, ShapeType)); CoordinateBuffer buffer = new CoordinateBuffer(1, NoDataBorderValue, true); IPrecisionModel precisionModel = factory.PrecisionModel; double x = precisionModel.MakePrecise(ReadDouble(file, totalRecordLength, ref totalRead)); double y = precisionModel.MakePrecise(ReadDouble(file, totalRecordLength, ref totalRead)); double? z = null, m = null; // Trond Benum: Let's read optional Z and M values if (HasZValue() && totalRead < totalRecordLength) z = ReadDouble(file, totalRecordLength, ref totalRead); if ((HasMValue() || HasZValue()) && (totalRead < totalRecordLength)) m = ReadDouble(file, totalRecordLength, ref totalRead); buffer.AddCoordinate(x, y, z, m); return factory.CreatePoint(buffer.ToSequence(factory.CoordinateSequenceFactory)); }
public void IntMinValueTest() { var coord = new Coordinate(300000, Int32.MinValue); var point = factory.CreatePoint(coord); var text = writer.Write(point); Assert.IsNotNull(text); Assert.AreEqual("POINT (300000 -2147483648)", text); }
public void TestAlbersProjection() { CoordinateSystemFactory cFac = new CoordinateSystemFactory(); IEllipsoid ellipsoid = cFac.CreateFlattenedSphere( "Clarke 1866", 6378206.4, 294.9786982138982, LinearUnit.USSurveyFoot); IHorizontalDatum datum = cFac.CreateHorizontalDatum( "Clarke 1866", DatumType.HD_Geocentric, ellipsoid, null); IGeographicCoordinateSystem gcs = cFac.CreateGeographicCoordinateSystem( "Clarke 1866", AngularUnit.Degrees, datum, PrimeMeridian.Greenwich, new AxisInfo("Lon", AxisOrientationEnum.East), new AxisInfo("Lat", AxisOrientationEnum.North)); List <ProjectionParameter> parameters = new List <ProjectionParameter>(5); parameters.Add(new ProjectionParameter("central_meridian", -96)); parameters.Add(new ProjectionParameter("latitude_of_center", 23)); parameters.Add(new ProjectionParameter("standard_parallel_1", 29.5)); parameters.Add(new ProjectionParameter("standard_parallel_2", 45.5)); parameters.Add(new ProjectionParameter("false_easting", 0)); parameters.Add(new ProjectionParameter("false_northing", 0)); IProjection projection = cFac.CreateProjection( "Albers Conical Equal Area", "albers", parameters); IProjectedCoordinateSystem coordsys = cFac.CreateProjectedCoordinateSystem( "Albers Conical Equal Area", gcs, projection, LinearUnit.Metre, new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North)); ICoordinateTransformation trans = new CoordinateTransformationFactory().CreateFromCoordinateSystems(gcs, coordsys); IGeometryFactory f = GeometryFactory.Default; IPoint pGeo = f.CreatePoint(new Coordinate(-75, 35)); IPoint pUtm = GeometryTransform.TransformPoint(f, pGeo, trans.MathTransform); IPoint pGeo2 = GeometryTransform.TransformPoint(f, pUtm, trans.MathTransform.Inverse()); IPoint expected = f.CreatePoint(new Coordinate(1885472.7, 1535925)); Assert.IsTrue(ToleranceLessThan(pUtm, expected, 0.05), String.Format("Albers forward transformation outside tolerance, Expected [{0},{1}], got [{2},{3}]", expected.X, expected.Y, pUtm.X, pUtm.Y)); Assert.IsTrue(ToleranceLessThan(pGeo, pGeo2, 0.0000001), String.Format("Albers reverse transformation outside tolerance, Expected [{0},{1}], got [{2},{3}]", pGeo.X, pGeo.Y, pGeo2.X, pGeo2.Y)); }
public IGeometry ToGeometry(IGeometryFactory geomFactory) { if (IsNull) { return(geomFactory.CreatePoint((ICoordinateSequence)null)); } Coordinate px00 = new Coordinate(_minX, _minA - _minX); Coordinate px01 = new Coordinate(_minX, _minX - _minB); Coordinate px10 = new Coordinate(_maxX, _maxX - _maxB); Coordinate px11 = new Coordinate(_maxX, _maxA - _maxX); Coordinate py00 = new Coordinate(_minA - _minY, _minY); Coordinate py01 = new Coordinate(_minY + _maxB, _minY); Coordinate py10 = new Coordinate(_maxY + _minB, _maxY); Coordinate py11 = new Coordinate(_maxA - _maxY, _maxY); IPrecisionModel pm = geomFactory.PrecisionModel; pm.MakePrecise(px00); pm.MakePrecise(px01); pm.MakePrecise(px10); pm.MakePrecise(px11); pm.MakePrecise(py00); pm.MakePrecise(py01); pm.MakePrecise(py10); pm.MakePrecise(py11); CoordinateList coordList = new CoordinateList(); coordList.Add(px00, false); coordList.Add(px01, false); coordList.Add(py10, false); coordList.Add(py11, false); coordList.Add(px11, false); coordList.Add(px10, false); coordList.Add(py01, false); coordList.Add(py00, false); if (coordList.Count == 1) { return(geomFactory.CreatePoint(px00)); } Coordinate[] pts; if (coordList.Count == 2) { pts = coordList.ToCoordinateArray(); return(geomFactory.CreateLineString(pts)); } // must be a polygon, so add closing point coordList.Add(px00, false); pts = coordList.ToCoordinateArray(); return(geomFactory.CreatePolygon(geomFactory.CreateLinearRing(pts), null)); }
public void RTreeContainsTest() { Assert.IsFalse(_tree.Contains(null)); Assert.IsFalse(_tree.Contains(_factory.CreatePoint(1000, 1000, 1000))); Assert.IsFalse(_tree.Contains(_factory.CreatePoint(Coordinate.Undefined))); foreach (IPoint geometry in _geometries) { Assert.IsTrue(_tree.Contains(geometry)); } }
/// <summary> /// Creates a <c>Point</c> using the next token in the stream. /// </summary> /// <param name="tokens"> /// Tokenizer over a stream of text in Well-known Text /// format. The next tokens must form a <Point Text. /// </param> /// <returns>A <c>Point</c> specified by the next token in /// the stream.</returns> private IPoint ReadPointText(IList tokens) { string nextToken = GetNextEmptyOrOpener(tokens); if (nextToken.Equals("EMPTY")) { return(geometryFactory.CreatePoint((ICoordinate)null)); } IPoint point = geometryFactory.CreatePoint(GetPreciseCoordinate(tokens, false)); GetNextCloser(tokens); return(point); }
/// <summary> /// Creates a <c>Point</c> using the next token in the stream. /// </summary> /// <param name="tokens"> /// Tokenizer over a stream of text in Well-known Text /// format. The next tokens must form a <Point Text. /// </param> /// <param name="factory"> </param> /// <returns>A <c>Point</c> specified by the next token in /// the stream.</returns> private IPoint ReadPointText(IEnumerator <Token> tokens, IGeometryFactory factory) { string nextToken = GetNextEmptyOrOpener(tokens); if (nextToken.Equals("EMPTY")) { return(factory.CreatePoint((Coordinate)null)); } IPoint point = factory.CreatePoint(GetPreciseCoordinate(tokens, false)); GetNextCloser(tokens); return(point); }
/// <summary> /// Creates a <c>Point</c> using the next token in the stream. /// </summary> /// <param name="tokens"> /// Tokenizer over a stream of text in Well-known Text /// format. The next tokens must form a <Point Text. /// </param> /// <param name="factory"> </param> /// <returns>A <c>Point</c> specified by the next token in /// the stream.</returns> private IPoint ReadPointText(IEnumerator <Token> tokens, IGeometryFactory factory) { var nextToken = GetNextEmptyOrOpener(tokens); if (nextToken.Equals("EMPTY")) { return(factory.CreatePoint((Coordinate)null)); } var hasZ = false; var coord = GetPreciseCoordinate(tokens, false, ref hasZ); var point = factory.CreatePoint(ToSequence(hasZ, coord)); /*var closer = */ GetNextCloser(tokens); return(point); }
private static IGeometry CreatePoint(Ordinates ordinates, bool empty) { if (empty) { return(Factory.CreatePoint((ICoordinateSequence)null)); } var seq = CsFactory.Create(1, ordinates); foreach (var o in OrdinatesUtility.ToOrdinateArray(ordinates)) { seq.SetOrdinate(0, o, RandomOrdinate(o, Factory.PrecisionModel)); } return(Factory.CreatePoint(seq)); }
/// <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> /// <param name="factory">The factory to create the result geometry</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 IPoint ReadPointText(WktStreamTokenizer tokenizer, IGeometryFactory factory) { var nextToken = GetNextEmptyOrOpener(tokenizer); if (nextToken == "EMPTY") { return(factory.CreatePoint((Coordinate)null)); } var c = new Coordinate(GetNextNumber(tokenizer), GetNextNumber(tokenizer)); GetNextCloser(tokenizer); return(factory.CreatePoint(c)); }
private IGeometry ToGeoAPIPoint(SpatialLite.Core.API.IPoint geometry) { var lst = new SpatialLite.Core.Geometries.CoordinateList(); lst.Add(geometry.Position); return(_factory.CreatePoint(_clConverter.ToSequence(lst))); }
/// <summary> /// Function to read a <see cref="IPoint"/> from a ShapeFile stream using the specified <paramref name="reader"/>. /// </summary> /// <param name="reader">The reader to use</param> /// <param name="ordinates">The ordinates to read</param> /// <returns>The read point geometry</returns> protected IGeometry ReadPoint(BinaryReader reader, Ordinates ordinates) { var buffer = new CoordinateBuffer(1, ShapeFileConstants.NoDataBorder, true); ReadCoordinates(reader, 1, new[] { 0 }, ordinates, buffer); IGeometry point = _factory.CreatePoint(buffer.ToSequence()); return point; }
/// <summary> /// Converts the specified Well-known Text (WKT) to a point. /// </summary> /// <param name="text">The WKT representation of the point.</param> /// <param name="dimension">The dimension of the geometry.</param> /// <param name="factory">The geometry factory.</param> /// <returns>The converted point.</returns> private static IPoint ToPoint(String text, Int32 dimension, IGeometryFactory factory) { Match match = Regex.Match(text, PatternCoordinate); if (dimension == 3) { return(factory.CreatePoint(Double.Parse(match.Groups["x"].Value, CultureInfo.InvariantCulture), Double.Parse(match.Groups["y"].Value, CultureInfo.InvariantCulture), Double.Parse(match.Groups["z"].Value, CultureInfo.InvariantCulture))); } else { return(factory.CreatePoint(Double.Parse(match.Groups["x"].Value, CultureInfo.InvariantCulture), Double.Parse(match.Groups["y"].Value, CultureInfo.InvariantCulture))); } }
protected override void BeforeSetup() { _geometryFactory = Substitute.For <IGeometryFactory>(); _geometryFactory.CreatePoint(Arg.Any <Coordinate>()) .Returns(c => new Point(c.Arg <Coordinate>().X, c.Arg <Coordinate>().Y)); }
public static IReadOnlyList <PointEntity> CreatePointEntities(IGeometryFactory factory) { var entities = new[] { new PointEntity { Id = PointEntity.WellKnownId, Point = factory.CreatePoint( new Coordinate(0, 0)) }, new PointEntity { Id = Guid.Parse("67A54C9B-4C3B-4B27-8B4E-C0335E50E551"), Point = null } }; foreach (var entity in entities) { entity.Geometry = entity.Point?.Copy(); entity.ConcretePoint = (Point)entity.Point?.Copy(); } return(entities); }
/// <summary> /// 离散Polygon /// </summary> /// <param name="polygon"></param> /// <param name="distance"></param> private IPolygon DiscretePolygon(IPolygon polygon, double distance) { string wkt = "PROJCS[\"<Custom Coordinate>\",GEOGCS[\"GCS_Beijing_1954\",DATUM[\"D_Beijing_1954\",SPHEROID[\"Krasovsky_1940\",6378245.0,298.3]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]],PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"false_easting\",64685.26],PARAMETER[\"false_northing\",-3267460.1405],PARAMETER[\"central_meridian\",120.0],PARAMETER[\"scale_factor\",1.0],PARAMETER[\"latitude_of_origin\",0.0],UNIT[\"Meter\",1.0]]"; ICoordinateReferenceSystem tempcrs = crsFactory.CreateFromWKT(wkt); IRing ring = polygon.ExteriorRing; IPolygon resPolygon = geoFactory.CreateGeometry(gviGeometryType.gviGeometryPolygon, gviVertexAttribute.gviVertexAttributeZ) as IPolygon; resPolygon.SpatialCRS = crs as ISpatialCRS; for (int i = 0; i < ring.PointCount - 1; i++) { IPoint point1 = ring.GetPoint(i); IPoint point2 = ring.GetPoint(i + 1); resPolygon.ExteriorRing.AppendPoint(point1); point1.Project(tempcrs as ISpatialCRS); point2.Project(tempcrs as ISpatialCRS); IVector3 p1 = point1.Position; IVector3 p2 = point2.Position; IEulerAngle angle = this.axRenderControl1.Camera.GetAimingAngles(p1, p2); p2.MultiplyByScalar(-1); double length = p1.Add(p2).Length; for (int j = 0; j < (int)(length / distance); j++) { IVector3 tempv3 = this.axRenderControl1.Camera.GetAimingPoint(p1, angle, (distance * (j + 1))); IPoint tempPoint = geoFactory.CreatePoint(gviVertexAttribute.gviVertexAttributeZ); tempPoint.Position = tempv3; tempPoint.SpatialCRS = tempcrs as ISpatialCRS; tempPoint.Project(crs as ISpatialCRS); resPolygon.ExteriorRing.AppendPoint(tempPoint); } } resPolygon.Close(); return(resPolygon); }
public IGeometry Edit(IGeometry geometry, IGeometryFactory factory) { var linearRing = geometry as ILinearRing; if (linearRing != null) { return(factory.CreateLinearRing(EditSequence( (linearRing).CoordinateSequence, geometry))); } var lineString = geometry as ILineString; if (lineString != null) { return(factory.CreateLineString(EditSequence( (lineString).CoordinateSequence, geometry))); } var point = geometry as IPoint; if (point != null) { return(factory.CreatePoint(EditSequence( (point).CoordinateSequence, geometry))); } return(geometry); }
private Coordinate[] CreateTestPoints(int nPts) { var pt = _geomFact.CreatePoint(new Coordinate(baseX, baseY)); var circle = pt.Buffer(2 * rectSize, nPts / 4); return(circle.Coordinates); }
/// <summary> /// Reads a stream and converts the shapefile record to an equilivant geometry object. /// </summary> /// <param name="file">The stream to read.</param> /// <param name="geometryFactory">The geometry factory to use when making the object.</param> /// <returns>The Geometry object that represents the shape file record.</returns> public override IGeometry Read(BigEndianBinaryReader file, IGeometryFactory geometryFactory) { int shapeTypeNum = file.ReadInt32(); type = (ShapeGeometryType) Enum.Parse(typeof(ShapeGeometryType), shapeTypeNum.ToString()); if (type == ShapeGeometryType.NullShape) return geometryFactory.CreateMultiPoint(new IPoint[] { }); if (!(type == ShapeGeometryType.MultiPoint || type == ShapeGeometryType.MultiPointM || type == ShapeGeometryType.MultiPointZ || type == ShapeGeometryType.MultiPointZM)) throw new ShapefileException("Attempting to load a non-multipoint as multipoint."); // Read and for now ignore bounds. int bblength = GetBoundingBoxLength(); bbox = new double[bblength]; for (; bbindex < 4; bbindex++) { double d = file.ReadDouble(); bbox[bbindex] = d; } // Read points int numPoints = file.ReadInt32(); IPoint[] points = new IPoint[numPoints]; for (int i = 0; i < numPoints; i++) { double x = file.ReadDouble(); double y = file.ReadDouble(); IPoint point = geometryFactory.CreatePoint(new Coordinate(x, y)); points[i] = point; } geom = geometryFactory.CreateMultiPoint(points); GrabZMValues(file); return geom; }
/// <summary> /// Get nearest deals. /// </summary> /// <param name="request"></param> /// <returns></returns> public async Task <PagedResult <DealDto> > GetNearestDeals(SearchDealsRequestDto request) { var currentLocation = geometryFactory.CreatePoint(new Coordinate(request.GeoEntry.Longitude, request.GeoEntry.Latitude)); return(await unitOfWork.GetRepository <Deal>() .SearchFor(e => e.Brand.Stores.Any(s => s.Location.Distance(currentLocation) <= request.GeoEntry.Radius) && (e.DealValidFrom <= DateTime.Now) && (DateTime.Now <= e.DealValidTo) && !(e.Brand.Disabled ?? false)) .Include(e => e.Brand) .Include(e => e.Images) .OrderBy(e => e.Name) .Select(e => new DealDto() { Name = e.Name, DealType = (DealType)e.DealType, Gender = (GenderType)e.Gender, Currency = e.Currency, DealValidFrom = e.DealValidFrom, DealValidTo = e.DealValidTo, IsActive = e.IsActive, OriginalPrice = e.OriginalPrice, Price = e.Price, BuyNowUrl = e.BuyNowUrl, MarketUrl = e.MarketUrl, CouponCode = e.CouponCode, Images = e.Images.Select(i => i.Path) }) .GetPagedResultAsync(request.Skip, request.Take)); }
public IGeometry Edit(IGeometry geometry, IGeometryFactory targetFactory) { var coordinates = geometry.Coordinates; if (geometry is LinearRing) { var edit = Edit(coordinates, geometry); return(targetFactory.CreateLinearRing(edit)); } if (geometry is LineString) { var edit = Edit(coordinates, geometry); return(targetFactory.CreateLineString(edit)); } if (geometry is Point) { var edit = Edit(coordinates, geometry); var coordinate = edit.Length > 0 ? edit[0] : null; return(targetFactory.CreatePoint(coordinate)); } return(geometry); }
public IGeometry Union() { PointLocator locater = new PointLocator(); // use a set to eliminate duplicates, as required for union var exteriorCoords = new HashSet <Coordinate>(); foreach (IPoint point in PointExtracter.GetPoints(_pointGeom)) { Coordinate coord = point.Coordinate; Location loc = locater.Locate(coord, _otherGeom); if (loc == Location.Exterior) { exteriorCoords.Add(coord); } } // if no points are in exterior, return the other geom if (exteriorCoords.Count == 0) { return(_otherGeom); } // make a puntal geometry of appropriate size var exteriorCoordsArray = new Coordinate[exteriorCoords.Count]; exteriorCoords.CopyTo(exteriorCoordsArray, 0); Array.Sort(exteriorCoordsArray); ICoordinateSequence coords = _geomFact.CoordinateSequenceFactory.Create(exteriorCoordsArray); IGeometry ptComp = coords.Count == 1 ? (IGeometry)_geomFact.CreatePoint(coords.GetCoordinate(0)) : _geomFact.CreateMultiPoint(coords); // add point component to the other geometry return(GeometryCombiner.Combine(ptComp, _otherGeom)); }
public void IPoint() { //Do various IPoint method calls to cover the point class with sufficient testing IPoint2D p0 = _geoFactory.CreatePoint() as IPoint2D; IPoint2D p1 = _geoFactory.CreatePoint2D(0, 0); IPoint2D p2 = _geoFactory.CreatePoint2D(450, 120); Assert.IsTrue(p0.IsEmpty); Assert.IsFalse(p1.IsEmpty); Assert.AreNotEqual(p0, p1); Assert.AreEqual(450, p2.X); Assert.AreEqual(120, p2.Y); Assert.AreNotSame(p2.Clone(), p2); p0 = _geoFactory.CreatePoint2D(p2.X + 100, 150); p0 = _geoFactory.CreatePoint2D(p0.X + p0.Y, p0.Y); Assert.AreEqual(_geoFactory.CreatePoint2D(700, 150), p0); Assert.AreEqual(p2.Coordinate, p2.Extents.Min); Assert.AreEqual(p2.Coordinate, p2.Extents.Max); Assert.IsTrue(p2.IsSimple); Assert.IsFalse(p2.IsEmpty); Assert.AreEqual(2, p2.OrdinateCount); Assert.AreEqual(_geoFactory.CreatePoint2D(400, 100), p2.Add(_geoFactory.CreatePoint2D(-50, -20))); Assert.AreEqual(_geoFactory.CreatePoint2D(500, 100), p2.Subtract(_geoFactory.CreatePoint2D(-50, 20))); Assert.AreEqual(_geoFactory.CreatePoint2D(900, 240), p2.Multiply(2)); Assert.AreEqual(0, p2.Dimension); Assert.AreEqual(450, p2[Ordinates.X]); Assert.AreEqual(120, p2[Ordinates.Y]); Assert.IsNull(p2.Boundary); Assert.AreEqual(p2.X.GetHashCode() ^ p2.Y.GetHashCode() ^ p2.IsEmpty.GetHashCode(), p2.GetHashCode()); Assert.Greater(p2.CompareTo(p1), 0); Assert.Less(p1.CompareTo(p2), 0); Assert.AreEqual(p2.CompareTo(_geoFactory.CreatePoint2D(450, 120)), 0); }
public IGeometry Edit(IGeometry geometry, IGeometryFactory targetFactory) { if (geometry is ILinearRing) { var cs = ((ILinearRing)geometry).CoordinateSequence; var edit = Edit(cs, geometry, targetFactory); return(targetFactory.CreateLinearRing(edit)); } if (geometry is ILineString) { var cs = ((ILineString)geometry).CoordinateSequence; var edit = Edit(cs, geometry, targetFactory); return(targetFactory.CreateLineString(edit)); } if (geometry is IPoint) { var cs = ((IPoint)geometry).CoordinateSequence; var edit = Edit(cs, geometry, targetFactory); return(targetFactory.CreatePoint(edit)); } return(geometry); }
private IGeometry BuildPoint() { var seq = _coordinateBuffer.ToSequence(_factory.CoordinateSequenceFactory); return(_factory.CreatePoint(seq)); //return _factory.CreatePoint(_coordinates[0]); }
/// <summary> /// Reads a stream and converts the shapefile record to an equilivant geometry object. /// </summary> /// <param name="file">The stream to read.</param> /// <param name="geometryFactory">The geometry factory to use when making the object.</param> /// <returns>The Geometry object that represents the shape file record.</returns> public override IGeometry Read(BigEndianBinaryReader file, IGeometryFactory geometryFactory) { int shapeTypeNum = file.ReadInt32(); ShapeGeometryTypes shapeType = (ShapeGeometryTypes)Enum.Parse(typeof(ShapeGeometryTypes), shapeTypeNum.ToString()); if (shapeType == ShapeGeometryTypes.NullShape) { return(null); } if (!(shapeType == ShapeGeometryTypes.MultiPoint || shapeType == ShapeGeometryTypes.MultiPointM || shapeType == ShapeGeometryTypes.MultiPointZ || shapeType == ShapeGeometryTypes.MultiPointZM)) { throw new ShapefileException("Attempting to load a non-multipoint as multipoint."); } // Read and for now ignore bounds. double[] box = new double[4]; for (int i = 0; i < 4; i++) { box[i] = file.ReadDouble(); } // Read points int numPoints = file.ReadInt32(); IPoint[] points = new IPoint[numPoints]; for (int i = 0; i < numPoints; i++) { points[i] = geometryFactory.CreatePoint(new Coordinate(file.ReadDouble(), file.ReadDouble())); } return(geometryFactory.CreateMultiPoint(points)); }
public static IGeometry Circumcentre(IGeometry g) { Coordinate[] pts = TrianglePts(g); Coordinate cc = Triangle.Circumcentre(pts[0], pts[1], pts[2]); IGeometryFactory geomFact = FunctionsUtil.GetFactoryOrDefault(g); return(geomFact.CreatePoint(cc)); }
public void SetUp() { _factory = new GeometryFactory(); _geometries = new IGeometry[] { _factory.CreatePoint(1, 1, 1), _factory.CreateLineString(Enumerable.Range(1, 4).Select(i => new Coordinate(i, i, i))), _factory.CreatePolygon(Enumerable.Range(1, 4).Select(i => new Coordinate(i * i, i * i, i * i)), new Coordinate[][] { Enumerable.Range(1, 100).Select(i => new Coordinate(i, i, i)).ToArray(), Enumerable.Range(1, 4).Select(i => new Coordinate(i, i, i)).ToArray() }), _factory.CreateMultiPoint(Enumerable.Range(1, 4).Select(i => _factory.CreatePoint(i, i, i))), _factory.CreateMultiLineString(new ILineString[] { _factory.CreateLineString(Enumerable.Range(1, 4).Select(i => new Coordinate(i, i, i))) }), _factory.CreateMultiPolygon(new IPolygon[] { _factory.CreatePolygon(Enumerable.Range(1, 4).Select(i => new Coordinate(i * i, i * i, i * i)), new Coordinate[][] { Enumerable.Range(1, 4).Select(i => new Coordinate(i, i, i)).ToArray(), Enumerable.Range(1, 4).Select(i => new Coordinate(i, i, i)).ToArray() }) }) }; }
private void ProcessPointGeometry(Point f) { var coords = new Coordinate(f.Coordinate.Longitude, f.Coordinate.Latitude); var pGeom = _geometryFactory.CreatePoint(coords); AddGeometryToCollection(f.GetParent <Placemark>(), pGeom); }
/// <summary> /// Reads a stream and converts the shapefile record to an equilivent geometry object. /// </summary> /// <param name="file">The stream to read.</param> /// <param name="geometryFactory">The geometry factory to use when making the object.</param> /// <returns>The Geometry object that represents the shape file record.</returns> public override IGeometry Read(BigEndianBinaryReader file, IGeometryFactory geometryFactory) { int shapeTypeNum = file.ReadInt32(); ShapeGeometryTypes shapeType = (ShapeGeometryTypes) Enum.Parse(typeof(ShapeGeometryTypes), shapeTypeNum.ToString()); if ( ! ( shapeType == ShapeGeometryTypes.Point || shapeType == ShapeGeometryTypes.PointM || shapeType == ShapeGeometryTypes.PointZ || shapeType == ShapeGeometryTypes.PointZM )) throw new ShapefileException("Attempting to load a point as point."); double x= file.ReadDouble(); double y= file.ReadDouble(); ICoordinate external = new Coordinate(x,y); geometryFactory.PrecisionModel.MakePrecise( external); return geometryFactory.CreatePoint(external); }
/// <summary> /// Reads a stream and converts the shapefile record to an equilivant geometry object. /// </summary> /// <param name="file">The stream to read.</param> /// <param name="totalRecordLength">Total length of the record we are about to read</param> /// <param name="geometryFactory">The geometry factory to use when making the object.</param> /// <returns>The Geometry object that represents the shape file record.</returns> public override IGeometry Read(BigEndianBinaryReader file, int totalRecordLength, IGeometryFactory geometryFactory) { int totalRead = 0; int shapeTypeNum = ReadInt32(file, totalRecordLength, ref totalRead); var type = (ShapeGeometryType) EnumUtility.Parse(typeof(ShapeGeometryType), shapeTypeNum.ToString()); if (type == ShapeGeometryType.NullShape) return geometryFactory.CreateMultiPoint(new IPoint[] { }); if (type != ShapeType) throw new ShapefileException(string.Format("Encountered a '{0}' instead of a '{1}'", type, ShapeType)); // Read and for now ignore bounds. int bblength = GetBoundingBoxLength(); boundingBox = new double[bblength]; for (; boundingBoxIndex < 4; boundingBoxIndex++) { double d = ReadDouble(file, totalRecordLength, ref totalRead); boundingBox[boundingBoxIndex] = d; } // Read points var numPoints = ReadInt32(file, totalRecordLength, ref totalRead); var buffer = new CoordinateBuffer(numPoints, NoDataBorderValue, true); var points = new IPoint[numPoints]; var pm = geometryFactory.PrecisionModel; for (var i = 0; i < numPoints; i++) { var x = pm.MakePrecise(ReadDouble(file, totalRecordLength, ref totalRead)); var y = pm.MakePrecise(ReadDouble(file, totalRecordLength, ref totalRead)); buffer.AddCoordinate(x, y); buffer.AddMarker(); } // Trond Benum: We have now read all the points, let's read optional Z and M values GetZMValues(file, totalRecordLength, ref totalRead, buffer); var sequences = buffer.ToSequences(geometryFactory.CoordinateSequenceFactory); for (var i = 0; i < numPoints; i++) points[i] = geometryFactory.CreatePoint(sequences[i]); geom = geometryFactory.CreateMultiPoint(points); return geom; }
/// <summary> /// Reads a stream and converts the shapefile record to an equilivent geometry object. /// </summary> /// <param name="file">The stream to read.</param> /// <param name="geometryFactory">The geometry factory to use when making the object.</param> /// <returns>The Geometry object that represents the shape file record.</returns> public override IGeometry Read(BigEndianBinaryReader file, IGeometryFactory geometryFactory) { int shapeTypeNum = file.ReadInt32(); ShapeGeometryTypes shapeType = (ShapeGeometryTypes)Enum.Parse(typeof(ShapeGeometryTypes), shapeTypeNum.ToString()); if ( ( shapeType == ShapeGeometryTypes.LineString || shapeType == ShapeGeometryTypes.LineStringM || shapeType == ShapeGeometryTypes.LineStringZ || shapeType == ShapeGeometryTypes.LineStringZM || shapeType == ShapeGeometryTypes.MultiPatch || shapeType == ShapeGeometryTypes.NullShape || shapeType == ShapeGeometryTypes.Polygon || shapeType == ShapeGeometryTypes.PolygonM || shapeType == ShapeGeometryTypes.PolygonZ || shapeType == ShapeGeometryTypes.PolygonZM )) throw new ShapefileException("Attempting to load a non-point shapefile as point."); double x= file.ReadDouble(); double y= file.ReadDouble(); Coordinate external = new Coordinate(x,y); // return geometryFactory.CreatePoint(geometryFactory.PrecisionModel.ToInternal(external)); new PrecisionModel(geometryFactory.PrecisionModel).MakePrecise(external); return geometryFactory.CreatePoint(external); }
/// <summary> /// Reads a stream and converts the shapefile record to an equilivant geometry object. /// </summary> /// <param name="file">The stream to read.</param> /// <param name="geometryFactory">The geometry factory to use when making the object.</param> /// <returns>The Geometry object that represents the shape file record.</returns> public override IGeometry Read(BigEndianBinaryReader file, IGeometryFactory geometryFactory) { int shapeTypeNum = file.ReadInt32(); ShapeGeometryTypes shapeType = (ShapeGeometryTypes) Enum.Parse(typeof(ShapeGeometryTypes), shapeTypeNum.ToString()); if ( ! ( shapeType == ShapeGeometryTypes.MultiPoint || shapeType == ShapeGeometryTypes.MultiPointM || shapeType == ShapeGeometryTypes.MultiPointZ || shapeType == ShapeGeometryTypes.MultiPointZM)) throw new ShapefileException("Attempting to load a non-multipoint as multipoint."); // Read and for now ignore bounds. double[] box = new double[4]; for (int i = 0; i < 4; i++) box[i] = file.ReadDouble(); // Read points int numPoints = file.ReadInt32(); IPoint[] points = new IPoint[numPoints]; for (int i = 0; i < numPoints; i++) points[i] = geometryFactory.CreatePoint(new Coordinate(file.ReadDouble(), file.ReadDouble())); return geometryFactory.CreateMultiPoint(points); }
/// <summary> /// Transforms a <see cref="GeoAPI.Geometries.IPoint"/>. /// </summary> /// <param name="p">Point to transform</param> /// <param name="from">The source Projection</param> /// <param name="to">The target Projection</param> /// <param name="toFactory">The factory to create geometries for <paramref name="to"/></param> /// <returns>Transformed Point</returns> public static IPoint TransformPoint(IPoint p, ProjectionInfo from, ProjectionInfo to, IGeometryFactory toFactory) { try { var toSeq = TransformSequence(p.CoordinateSequence, from, to, toFactory.CoordinateSequenceFactory); return toFactory.CreatePoint(toSeq); } catch { return null; } }
/// <summary> /// /// </summary> /// <param name="geometry"></param> /// <param name="factory"></param> /// <returns></returns> public IGeometry Edit(IGeometry geometry, IGeometryFactory factory) { if (geometry is ILinearRing) return factory.CreateLinearRing(Edit(geometry.Coordinates, geometry)); if (geometry is ILineString) return factory.CreateLineString(Edit(geometry.Coordinates, geometry)); if (geometry is Point) { ICoordinate[] newCoordinates = Edit(geometry.Coordinates, geometry); return factory.CreatePoint((newCoordinates.Length > 0) ? newCoordinates[0] : null); } return geometry; }
/// <summary> /// Creates an array of <c>Point</c>s having the given <c>Coordinate</c>s. /// </summary> /// <param name="coordinates"> /// The <c>Coordinate</c>s with which to create the <c>Point</c>s /// </param> /// <param name="factory">The factory to create the points</param> /// <returns> /// <c>Point</c>s created using this <c>WKTReader</c> /// s <c>GeometryFactory</c>. /// </returns> private IPoint[] ToPoints(ICoordinateSequence coordinates, IGeometryFactory factory) { var points = new IPoint[coordinates.Count]; for (var i = 0; i < coordinates.Count; i++) { var cs = _coordinateSequencefactory.Create(1, coordinates.Ordinates); CoordinateSequences.Copy(coordinates, i, cs, 0, 1); points[i] = factory.CreatePoint(cs); } return points; }
private static IPoint RandomPoint(IGeometryFactory geometryFactory) { return geometryFactory.CreatePoint(RandomCoordinate(geometryFactory.CoordinateFactory)); }
/// <summary> /// Transforms a <see cref="Point" /> object. /// </summary> /// <param name="factory"></param> /// <param name="p"></param> /// <param name="transform"></param> /// <returns></returns> public static IPoint TransformPoint(IGeometryFactory factory, IPoint p, IMathTransform transform) { try { var transformed = transform.Transform(p.CoordinateSequence); return factory.CreatePoint(transformed); } catch { return null; } }
/// <summary> /// Get the point for this shape if this is a point shape. /// </summary> /// <param name="factory"></param> /// <returns></returns> protected IGeometry FromPoint(IGeometryFactory factory) { if (factory == null) factory = Geometry.DefaultFactory; foreach (PartRange part in _shapeRange.Parts) { foreach (Vertex vertex in part) { Coordinate c = new Coordinate(vertex.X, vertex.Y); return factory.CreatePoint(c); } } return null; }
/// <summary> /// See http://www.gaia-gis.it/gaia-sins/BLOB-Geometry.html /// for the specification of the spatialite BLOB geometry format /// Derived from WKB, but unfortunately it is not practical to reuse existing /// WKB encoding/decoding code /// </summary> /// <param name="spatialliteGeom">The geometry blob</param> /// <param name="factory">The factory to create the result geometry</param> /// <returns>A geometry</returns> public static IGeometry Parse(byte[] spatialliteGeom, IGeometryFactory factory) { var nBytes = spatialliteGeom.Length; if (spatialliteGeom.Length < 44 || spatialliteGeom[0] != 0 || spatialliteGeom[38] != 0x7C || spatialliteGeom[nBytes - 1] != 0xFE) throw new ApplicationException("Corrupt SpatialLite geom"); bool isLittleEndian = spatialliteGeom[1] == 0x01; if (spatialliteGeom[1] != 0x00 && spatialliteGeom[1] != 0x01) throw new ApplicationException("Corrupt SpatialLite geom"); int idx = 39; int nGType = ReadUInt32(spatialliteGeom, ref idx, isLittleEndian); if (nGType < 1 || nGType > 7) throw new ApplicationException("Unsupported geom type!"); /* -------------------------------------------------------------------- */ /* Point */ /* -------------------------------------------------------------------- */ if (nGType == 1) { return factory.CreatePoint(ReadPoint(spatialliteGeom, ref idx, isLittleEndian)); } /* -------------------------------------------------------------------- */ /* LineString */ /* -------------------------------------------------------------------- */ else if (nGType == 2) { return ReadLineString(spatialliteGeom, ref idx, isLittleEndian, factory); } /* -------------------------------------------------------------------- */ /* Polygon */ /* -------------------------------------------------------------------- */ else if (nGType == 3) { return ReadPolygon(spatialliteGeom, ref idx, isLittleEndian, factory); } /* -------------------------------------------------------------------- */ /* MultiPoint */ /* -------------------------------------------------------------------- */ else if (nGType == 4) { List<GeoAPI.Geometries.IPoint> pts = new List<GeoAPI.Geometries.IPoint>(); int numGeoms = ReadUInt32(spatialliteGeom, ref idx, isLittleEndian); for (int i = 0; i < numGeoms; i++) { if (spatialliteGeom[idx] != 0x69) throw new ApplicationException("FormatError in SpatiaLIteGeom"); idx++; int gt = ReadUInt32(spatialliteGeom, ref idx, isLittleEndian); if (gt != 1) throw new ApplicationException("MultiPoint must Contain Point entities"); pts.Add(factory.CreatePoint(ReadPoint(spatialliteGeom, ref idx, isLittleEndian))); } return factory.CreateMultiPoint(pts.ToArray()); } /* -------------------------------------------------------------------- */ /* MultiLineString */ /* -------------------------------------------------------------------- */ else if (nGType == 5) { List<GeoAPI.Geometries.ILineString> lss = new List<GeoAPI.Geometries.ILineString>(); int numGeoms = ReadUInt32(spatialliteGeom, ref idx, isLittleEndian); for (int i = 0; i < numGeoms; i++) { if (spatialliteGeom[idx] != 0x69) throw new ApplicationException("FormatError in SpatiaLIteGeom"); idx++; int gt = ReadUInt32(spatialliteGeom, ref idx, isLittleEndian); if (gt != 2) throw new ApplicationException("MultiLineString must contain LineString Entities"); lss.Add(ReadLineString(spatialliteGeom, ref idx, isLittleEndian, factory)); } return factory.CreateMultiLineString(lss.ToArray()); } /* -------------------------------------------------------------------- */ /* MultiPolygon */ /* -------------------------------------------------------------------- */ else if (nGType == 6) { List<GeoAPI.Geometries.IPolygon> polys = new List<GeoAPI.Geometries.IPolygon>(); int numPolys = ReadUInt32(spatialliteGeom, ref idx, isLittleEndian); for (int i = 0; i < numPolys; i++) { if (spatialliteGeom[idx] != 0x69) throw new ApplicationException("FormatError in SpatiaLIteGeom"); idx++; int gt = ReadUInt32(spatialliteGeom, ref idx, isLittleEndian); if (gt != 3) throw new ApplicationException("Multipolygon must contain Polygon Entities"); polys.Add(ReadPolygon(spatialliteGeom, ref idx, isLittleEndian, factory)); } return factory.CreateMultiPolygon(polys.ToArray()); } return null; }
private IPoint ReprojectPoint(IGeometryFactory factory, IPoint point, ISpatialReference @from, ISpatialReference to) { return factory.CreatePoint(Reproject(point.CoordinateSequence, from, to)); }
private static IPoint CreateWKBPoint(BinaryReader reader, WkbByteOrder byteOrder, IGeometryFactory factory) { // Create and return the point. return factory.CreatePoint(new Coordinate(ReadDouble(reader, byteOrder), ReadDouble(reader, byteOrder))); }
/// <summary> /// Creates an array of <c>Point</c>s having the given <c>Coordinate</c>s. /// </summary> /// <param name="coordinates"> /// The <c>Coordinate</c>s with which to create the <c>Point</c>s /// </param> /// <param name="factory">The factory to create the points</param> /// <returns> /// <c>Point</c>s created using this <c>WKTReader</c> /// s <c>GeometryFactory</c>. /// </returns> private static IPoint[] ToPoints(Coordinate[] coordinates, IGeometryFactory factory) { var points = new IPoint[coordinates.Length]; for (var i = 0; i < coordinates.Length; i++) points[i] = factory.CreatePoint(coordinates[i]); return points; }
private static void GeneratePoints(IGeometryFactory factory, ICollection<IGeometry> geometry, Random rndGen) { var numPoints = rndGen.Next(10, 100); for (var pointIndex = 0; pointIndex < numPoints; pointIndex++) { var point = new GeoPoint(rndGen.NextDouble()*1000, rndGen.NextDouble()*1000); geometry.Add(factory.CreatePoint(point)); } }
public IGeometry ToGeometry(IGeometryFactory geomFactory) { if (IsNull) { return geomFactory.CreatePoint((ICoordinateSequence)null); } Coordinate px00 = new Coordinate(_minX, _minA - _minX); Coordinate px01 = new Coordinate(_minX, _minX - _minB); Coordinate px10 = new Coordinate(_maxX, _maxX - _maxB); Coordinate px11 = new Coordinate(_maxX, _maxA - _maxX); Coordinate py00 = new Coordinate(_minA - _minY, _minY); Coordinate py01 = new Coordinate(_minY + _maxB, _minY); Coordinate py10 = new Coordinate(_maxY + _minB, _maxY); Coordinate py11 = new Coordinate(_maxA - _maxY, _maxY); IPrecisionModel pm = geomFactory.PrecisionModel; pm.MakePrecise(px00); pm.MakePrecise(px01); pm.MakePrecise(px10); pm.MakePrecise(px11); pm.MakePrecise(py00); pm.MakePrecise(py01); pm.MakePrecise(py10); pm.MakePrecise(py11); CoordinateList coordList = new CoordinateList(); coordList.Add(px00, false); coordList.Add(px01, false); coordList.Add(py10, false); coordList.Add(py11, false); coordList.Add(px11, false); coordList.Add(px10, false); coordList.Add(py01, false); coordList.Add(py00, false); if (coordList.Count == 1) { return geomFactory.CreatePoint(px00); } Coordinate[] pts; if (coordList.Count == 2) { pts = coordList.ToCoordinateArray(); return geomFactory.CreateLineString(pts); } // must be a polygon, so add closing point coordList.Add(px00, false); pts = coordList.ToCoordinateArray(); return geomFactory.CreatePolygon(geomFactory.CreateLinearRing(pts), null); }
private static IPoint ParseWkbPoint(byte[] blob, ref int offset, IGeometryFactory factory, ReadCoordinatesFunction readCoordinates, GaiaImport gaiaImport) { return factory.CreatePoint(readCoordinates(blob, ref offset, 1, gaiaImport, factory.CoordinateSequenceFactory, factory.PrecisionModel)); }
/// <summary> /// /// </summary> /// <param name="geometry"></param> /// <param name="factory"></param> /// <returns></returns> public virtual IGeometry Edit(IGeometry geometry, IGeometryFactory factory) { if (geometry is LinearRing) return factory.CreateLinearRing(Edit(geometry.Coordinates, geometry)); if (geometry is LineString) return factory.CreateLineString(Edit(geometry.Coordinates, geometry)); if (geometry is Point) { IList<Coordinate> newCoordinates = Edit(geometry.Coordinates, geometry); return factory.CreatePoint((newCoordinates.Count > 0) ? newCoordinates[0] : null); } return geometry; }
/// <summary> /// Get the point for this shape if this is a point shape. /// </summary> /// <param name="factory"></param> /// <returns></returns> protected IGeometry FromPoint(IGeometryFactory factory) { if (factory == null) factory = Geometry.DefaultFactory; foreach (var part in _shapeRange.Parts) { foreach (var vertex in part) { var c = GetCoordinate(vertex, part.StartIndex); return factory.CreatePoint(c); } } return null; }
/// <summary> /// Creates a <c>Point</c> using the next token in the stream. /// </summary> /// <param name="tokens"> /// Tokenizer over a stream of text in Well-known Text /// format. The next tokens must form a <Point Text. /// </param> /// <param name="factory"> </param> /// <returns>A <c>Point</c> specified by the next token in /// the stream.</returns> private IPoint ReadPointText(IEnumerator<Token> tokens, IGeometryFactory factory) { var nextToken = GetNextEmptyOrOpener(tokens); if (nextToken.Equals("EMPTY")) return factory.CreatePoint((Coordinate) null); var hasZ = false; var coord = GetPreciseCoordinate(tokens, false, ref hasZ); var point = factory.CreatePoint(ToSequence(hasZ, coord)); /*var closer = */GetNextCloser(tokens); return point; }
public IGeometry Edit(IGeometry geometry, IGeometryFactory factory) { var linearRing = geometry as ILinearRing; if (linearRing != null) { return factory.CreateLinearRing(EditSequence( (linearRing).CoordinateSequence, geometry)); } var lineString = geometry as ILineString; if (lineString != null) { return factory.CreateLineString(EditSequence( (lineString).CoordinateSequence, geometry)); } var point = geometry as IPoint; if (point != null) { return factory.CreatePoint(EditSequence( (point).CoordinateSequence, geometry)); } return geometry; }
/// <summary> /// Transforms a <see cref="GeoAPI.Geometries.IPoint"/>. /// </summary> /// <param name="p">Point to transform</param> /// <param name="transform">MathTransform</param> /// <param name="targetFactory">The factory to create the target geometry</param> /// <returns>Transformed Point</returns> public static IPoint TransformPoint(IPoint p, IMathTransform transform, IGeometryFactory targetFactory) { try { return targetFactory.CreatePoint(TransformCoordinate(p.Coordinate, transform)); } catch { return null; } }
/// <summary> /// /// </summary> /// <param name="factory"></param> /// <param name="x"></param> /// <param name="y"></param> /// <returns></returns> private static IPoint ToNTS(IGeometryFactory factory, double x, double y) { return factory.CreatePoint(new Coordinate(x, y)); }
internal static NTSPoint ToNTSPoint(Geometries.Point point, IGeometryFactory factory) { return factory.CreatePoint(ToNTSCoordinate(point, factory)); }
/// <summary> /// Creates an empty result geometry of the appropriate dimension, /// based on the given overlay operation and the dimensions of the inputs. /// The created geometry is always an atomic geometry, /// not a collection. /// <para/> /// The empty result is constructed using the following rules: /// <list type="Bullet"> /// <item><see cref="SpatialFunction.Intersection"/> - result has the dimension of the lowest input dimension</item> /// <item><see cref="SpatialFunction.Union"/> - result has the dimension of the highest input dimension</item> /// <item><see cref="SpatialFunction.Difference"/> - result has the dimension of the left-hand input</item> /// <item><see cref="SpatialFunction.SymDifference"/> - result has the dimension of the highest input dimension /// (since symDifference is the union of the differences).</item> /// </list> /// </summary> /// <param name="overlayOpCode">The overlay operation being performed</param> /// <param name="a">An input geometry</param> /// <param name="b">An input geometry</param> /// <param name="geomFact">The geometry factory being used for the operation</param> /// <returns>An empty atomic geometry of the appropriate dimension</returns> public static IGeometry CreateEmptyResult(SpatialFunction overlayOpCode, IGeometry a, IGeometry b, IGeometryFactory geomFact) { IGeometry result = null; switch (ResultDimension(overlayOpCode, a, b)) { case Dimension.False: result = geomFact.CreateGeometryCollection(new IGeometry[0]); break; case Dimension.Point: result = geomFact.CreatePoint((Coordinate)null); break; case Dimension.Curve: result = geomFact.CreateLineString((Coordinate[])null); break; case Dimension.Surface: result = geomFact.CreatePolygon(null, null); break; } return result; }
/// <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> /// <param name="factory">The factory to create the result geometry</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 IPoint ReadPointText(WktStreamTokenizer tokenizer, IGeometryFactory factory) { var nextToken = GetNextEmptyOrOpener(tokenizer); if (nextToken == "EMPTY") return factory.CreatePoint((Coordinate)null); var c = new Coordinate(GetNextNumber(tokenizer), GetNextNumber(tokenizer)); GetNextCloser(tokenizer); return factory.CreatePoint(c); }
private static IGeometry CreatePoint(IGeometryFactory factory, Size size) { return factory.CreatePoint(new Coordinate(size.Width/2d, size.Height/2d)); }