public void PolygonArea() { var coords = new Coordinate[20]; var rnd = new Random(); var center = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90); var coordscheck = new GeoAPI.Geometries.Coordinate[20]; for (var 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); var x = coords[i].X; var y = coords[i].Y; var c = new GeoAPI.Geometries.Coordinate(x, y); coordscheck[i] = c; } coordscheck[19] = new GeoAPI.Geometries.Coordinate(coordscheck[0].X, coordscheck[0].Y); coords[19] = new Coordinate(coords[0].X, coords[0].Y); var gf = new NetTopologySuite.Geometries.GeometryFactory(); var ring = gf.CreateLinearRing(coordscheck); var polygonCheck = gf.CreatePolygon(ring, null); var pg = new Polygon(coords); var areaCheck = polygonCheck.Area; var area = pg.Area; Assert.IsTrue(Math.Abs(area - areaCheck) < 1e-6); }
public void Multils() { var rnd = new Random(); var ls = new LineString[40]; var lscheck = new GeoAPI.Geometries.ILineString[40]; var gf = new NetTopologySuite.Geometries.GeometryFactory(); for (var ii = 0; ii < 40; ii++) { var coord = new Coordinate[36]; var coordcheck = new GeoAPI.Geometries.Coordinate[36]; for (var i = 0; i < 36; i++) { coord[i] = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90); var x = coord[i].X; var y = coord[i].Y; var c = new GeoAPI.Geometries.Coordinate(x, y); coordcheck[i] = c; } ls[ii] = new LineString(coord); lscheck[ii] = gf.CreateLineString(coordcheck); } var mls = new MultiLineString(ls); var mlscheck = gf.CreateMultiLineString(lscheck); for (var 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); }
/// <summary> /// Creates a FeatureDataTable from arrays of x, y and z components /// </summary> /// <param name="xcomponents">an array of doubles representing the x ordinate values</param> /// <param name="ycomponents">an array of doubles representing the y ordinate values</param> /// <param name="zcomponents">an array of doubles representing the z ordinate values</param> /// <returns></returns> public static SharpMap.Data.FeatureDataTable CreatePointFeatureDataTableFromArrays(double[] xcomponents, double[] ycomponents, double[] zcomponents) { var factory = new NetTopologySuite.Geometries.GeometryFactory(); var threedee = false; if (zcomponents != null) { if (!(zcomponents.Length == ycomponents.Length && zcomponents.Length == xcomponents.Length)) throw new System.ApplicationException("Mismatched Array Lengths"); threedee = true; } else { if (ycomponents.Length != xcomponents.Length) throw new System.ApplicationException("Mismatched Array Lengths"); } var fdt = new SharpMap.Data.FeatureDataTable(); fdt.Columns.Add("TimeStamp", typeof (System.DateTime)); // add example timestamp attribute for (var i = 0; i < xcomponents.Length; i++) { SharpMap.Data.FeatureDataRow fdr = fdt.NewRow(); fdr.Geometry = factory.CreatePoint(threedee ? new GeoAPI.Geometries.Coordinate(xcomponents[i], ycomponents[i], zcomponents[i]) : new GeoAPI.Geometries.Coordinate(xcomponents[i], ycomponents[i])); fdr["TimeStamp"] = System.DateTime.Now; //set the timestamp property fdt.AddRow(fdr); } return fdt; }
/// <summary> /// 通过射线来判定第一个相交的要素 /// </summary> /// <param name="ray"></param> /// <returns></returns> public bool GetSelectedFeatureByRayCasting(Ray ray) { //计算Ray于地球的交点 bool isIntersect = _scene.Ellipsoid.Intersections(ray, out Geodetic2D result); //ImGui.Text(string.Format("Latitude:{0},logitude:{1}",result.Latitude,result.Longitude)); SelectedFeatures.Clear(); var geoFactory = new NetTopologySuite.Geometries.GeometryFactory(); if (isIntersect) { //是否考虑根据当前精度生成一个合适的Enve //这里一律采用0.001经纬度的精度 var env = new GeoAPI.Geometries.Envelope(new Coordinate(result.Longitude * 180 / Math.PI - 0.001, result.Latitude * 180 / Math.PI - 0.001), new Coordinate(result.Longitude * 180 / Math.PI + 0.001, result.Latitude * 180 / Math.PI + 0.001)); var selectedff = _quadTree.Query(env); foreach (var item in selectedff) { if (item.Geometry.Intersects(geoFactory.ToGeometry(env))) { SelectedFeatures.Add(item); } } return(true); } return(false); }
public bool ConvertJsonToShapeFileNew(string json, string shapeFilePath, string namefile) { string geometryString = ConvertGeometryToString(json); var attributesTable = new NetTopologySuite.Features.AttributesTable(); var attributes = AddAttribute(json); var geomFactory = new NetTopologySuite.Geometries.GeometryFactory(new NetTopologySuite.Geometries.PrecisionModel(), 4326); var wktReader = new WKTReader(geomFactory); var geometry = wktReader.Read(geometryString); string filesPathName = shapeFilePath.Substring(0, shapeFilePath.Length - 4); removeShapeFileIfExists(filesPathName); if (attributes != null) { attributesTable = attributes; var features = new List <NetTopologySuite.Features.IFeature> { new NetTopologySuite.Features.Feature(geometry, attributesTable) }; var name = namefile.Substring(0, namefile.Length - 4); // Create the directory where we will save the shapefile //var shapeFilePath = Path.Combine(Server.MapPath("~/Document"), name); if (!Directory.Exists(filesPathName)) { Directory.CreateDirectory(filesPathName); } // Construct the shapefile name. Don't add the .shp extension or the ShapefileDataWriter will // produce an unwanted shapefile var shapeFileName = Path.Combine(filesPathName, name); var shapeFilePrjName = Path.Combine(filesPathName, $"{name}.prj"); // Create the shapefile var outGeomFactory = NetTopologySuite.Geometries.GeometryFactory.Default; var writer = new ShapefileDataWriter(shapeFileName, outGeomFactory, Encoding.UTF8); var outDbaseHeader = ShapefileDataWriter.GetHeader(features[0], features.Count, Encoding.UTF8); writer.Header = outDbaseHeader; writer.Write(features); // Create the projection file using (var streamWriter = new StreamWriter(shapeFilePrjName)) { streamWriter.Write(GeographicCoordinateSystem.WGS84.WKT); } System.IO.File.WriteAllText(Path.Combine(filesPathName, $"{name}.cpg"), Encoding.UTF8.HeaderName); //var shapeFileReader = new ShapefileDataReader(shapeFileName, NetTopologySuite.Geometries.GeometryFactory.Default, Encoding.UTF8); //var read = shapeFileReader.Read(); //var values = new object[shapeFileReader.FieldCount - 1]; //var a = values[1]; //var a1 = shapeFileReader.GetName(0); //var geom = shapeFileReader.Geometry; string zipName = filesPathName + ".zip"; CompressToZipFile(new List <string>() { shapeFileName + ".shp", shapeFileName + ".dbf", shapeFileName + ".prj", shapeFileName + ".shx", shapeFileName + ".cpg" }, zipName); return(true); } return(false); }
public static Extent ConvertToMercatore(Extent extent) { NetTopologySuite.Geometries.PrecisionModel precisionModel = new NetTopologySuite.Geometries.PrecisionModel(GeoAPI.Geometries.PrecisionModels.Floating); CoordinateSystem wgs84 = GeographicCoordinateSystem.WGS84 as CoordinateSystem; CoordinateSystem mercatore = ProjectedCoordinateSystem.WebMercator as CoordinateSystem; ICoordinateSystemFactory cFac = new CoordinateSystemFactory(); int SRID_wgs84 = Convert.ToInt32(wgs84.AuthorityCode); //WGS84 SRID int SRID_mercatore = Convert.ToInt32(mercatore.AuthorityCode); //Mercatore SRID ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory ctFact = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory(); GeoAPI.CoordinateSystems.Transformations.ICoordinateTransformation transformation = ctFact.CreateFromCoordinateSystems(wgs84, mercatore); NetTopologySuite.Geometries.GeometryFactory factory_wgs84 = new NetTopologySuite.Geometries.GeometryFactory(precisionModel, SRID_wgs84); var bottomLeft = factory_wgs84.CreatePoint(new GeoAPI.Geometries.Coordinate(extent.Left, extent.Bottom, 0)); var topRight = factory_wgs84.CreatePoint(new GeoAPI.Geometries.Coordinate(extent.Right, extent.Top, 0)); double[] coords_bl = transformation.MathTransform.Transform(new double[] { bottomLeft.X, bottomLeft.Y }); double[] coords_tr = transformation.MathTransform.Transform(new double[] { topRight.X, topRight.Y }); NetTopologySuite.Geometries.GeometryFactory factory_mercatore = new NetTopologySuite.Geometries.GeometryFactory(precisionModel, SRID_mercatore); var p1_bl = factory_mercatore.CreatePoint(new GeoAPI.Geometries.Coordinate(coords_bl[0], coords_bl[1])); var p2_tr = factory_mercatore.CreatePoint(new GeoAPI.Geometries.Coordinate(coords_tr[0], coords_tr[1])); return new Extent(p1_bl.X, p1_bl.Y, p2_tr.X, p2_tr.Y); }
public void PolygonEnvelopeArea() { var coords = new Coordinate[20]; var rnd = new Random(); var center = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90); var coordscheck = new GeoAPI.Geometries.Coordinate[20]; for (var 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); var x = coords[i].X; var y = coords[i].Y; var c = new GeoAPI.Geometries.Coordinate(x, y); coordscheck[i] = c; } coordscheck[19] = new GeoAPI.Geometries.Coordinate(coords[0].X, coords[0].Y); coords[19] = new Coordinate(coords[0].X, coords[0].Y); var gf = new NetTopologySuite.Geometries.GeometryFactory(); GeoAPI.Geometries.ILinearRing ring = gf.CreateLinearRing(coordscheck); GeoAPI.Geometries.IPolygon pgcheck = gf.CreatePolygon(ring, null); var pg = new Polygon(coords); var area = pg.Envelope.Area(); AssertExt.AreEqual15(area, pgcheck.Envelope.Area); }
public SharpMap.Geometries.MultiLineString SplitLineString( SharpMap.Geometries.LineString lineString, System.Double length) { if (lineString == null || lineString.IsEmpty()) throw new System.ArgumentException("Linestring is null or Empty", "lineString"); var gf = new NetTopologySuite.Geometries.GeometryFactory(); var ntsLine = (NetTopologySuite.Geometries.LineString) SharpMap.Converters.NTS.GeometryConverter.ToNTSGeometry(lineString, gf); var ret = new SharpMap.Geometries.MultiLineString(); var lil = new NetTopologySuite.LinearReferencing.LengthIndexedLine(ntsLine); double currentLength = 0d; while (currentLength < ntsLine.Length) { var tmpLine = (NetTopologySuite.Geometries.LineString) lil.ExtractLine(currentLength, currentLength + length); ret.LineStrings.Add((SharpMap.Geometries.LineString) SharpMap.Converters.NTS.GeometryConverter.ToSharpMapGeometry(tmpLine)); currentLength += length; } return ret; }
public static GisPoint ConvertToMercatore(GisPoint point) { NetTopologySuite.Geometries.PrecisionModel precisionModel = new NetTopologySuite.Geometries.PrecisionModel(GeoAPI.Geometries.PrecisionModels.Floating); CoordinateSystem wgs84 = GeographicCoordinateSystem.WGS84 as CoordinateSystem; CoordinateSystem mercatore = ProjectedCoordinateSystem.WebMercator as CoordinateSystem; ICoordinateSystemFactory cFac = new CoordinateSystemFactory(); int SRID_wgs84 = Convert.ToInt32(wgs84.AuthorityCode); //WGS84 SRID int SRID_mercatore = Convert.ToInt32(mercatore.AuthorityCode); //Mercatore SRID ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory ctFact = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory(); GeoAPI.CoordinateSystems.Transformations.ICoordinateTransformation transformation = ctFact.CreateFromCoordinateSystems(wgs84, mercatore); NetTopologySuite.Geometries.GeometryFactory factory_wgs84 = new NetTopologySuite.Geometries.GeometryFactory(precisionModel, SRID_wgs84); var convertedPoint = factory_wgs84.CreatePoint(new GeoAPI.Geometries.Coordinate(point.X, point.Y, 0)); double[] coords = transformation.MathTransform.Transform(new double[] { convertedPoint.X, convertedPoint.Y }); NetTopologySuite.Geometries.GeometryFactory factory_mercatore = new NetTopologySuite.Geometries.GeometryFactory(precisionModel, SRID_mercatore); var p1 = factory_mercatore.CreatePoint(new GeoAPI.Geometries.Coordinate(coords[0], coords[1])); return new GisPoint(p1.X, p1.Y); }
/// <summary> /// Get an array of parcels within the specified filter. /// Will not return sensitive parcels unless the user has the `sensitive-view` claim and belongs to the owning agency. /// </summary> /// <param name="neLat"></param> /// <param name="neLong"></param> /// <param name="swLat"></param> /// <param name="swLong"></param> /// <returns></returns> public IEnumerable <Parcel> Get(double neLat, double neLong, double swLat, double swLong) { this.User.ThrowIfNotAuthorized(Permissions.PropertyView); // Check if user has the ability to view sensitive properties. var userAgencies = this.User.GetAgenciesAsNullable(); var viewSensitive = this.User.HasPermission(Security.Permissions.SensitiveView); var isAdmin = this.User.HasPermission(Permissions.AdminProperties); // Users may only view sensitive properties if they have the `sensitive-view` claim and belong to the owning agency. var query = this.Context.Parcels.AsNoTracking().Where(p => (isAdmin || p.IsVisibleToOtherAgencies || ((!p.IsSensitive || viewSensitive) && userAgencies.Contains(p.AgencyId)))); var pfactory = new NetTopologySuite.Geometries.GeometryFactory(); var ring = new NetTopologySuite.Geometries.LinearRing( new[] { new NetTopologySuite.Geometries.Coordinate(neLong, neLat), new NetTopologySuite.Geometries.Coordinate(swLong, neLat), new NetTopologySuite.Geometries.Coordinate(swLong, swLat), new NetTopologySuite.Geometries.Coordinate(neLong, swLat), new NetTopologySuite.Geometries.Coordinate(neLong, neLat) }); var poly = pfactory.CreatePolygon(ring); poly.SRID = 4326; query = query.Where(p => poly.Contains(p.Location)); return(query.ToArray()); }
public void PolygonCentroid() { var coords = new Coordinate[20]; var rnd = new Random(); var center = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90); var coordscheck = new GeoAPI.Geometries.Coordinate[20]; for (var 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); var x = coords[i].X; var y = coords[i].Y; var c = new GeoAPI.Geometries.Coordinate(x, y); coordscheck[i] = c; } coordscheck[19] = new GeoAPI.Geometries.Coordinate(coords[0].X, coords[0].Y); coords[19] = new Coordinate(coords[0].X, coords[0].Y); var gf = new NetTopologySuite.Geometries.GeometryFactory(); var ring = gf.CreateLinearRing(coordscheck); var polygonCheck = gf.CreatePolygon(ring, null); var pg = new Polygon(coords); var x1 = pg.Centroid.X; var x2 = polygonCheck.Centroid.X; AssertExt.AreEqual15(x1, x2); var y1 = pg.Centroid.Y; var y2 = polygonCheck.Centroid.Y; AssertExt.AreEqual15(y1, y2); }
private void CreateMatrix() { var f = new NetTopologySuite.Geometries.GeometryFactory(); _matrix = new ODMatrix(new[] { new KeyValuePair <ushort, GeoPoint>(0, f.CreatePoint(new Coordinate(-10, -10))), new KeyValuePair <ushort, GeoPoint>(1, f.CreatePoint(new Coordinate(-10, 10))), new KeyValuePair <ushort, GeoPoint>(2, f.CreatePoint(new Coordinate(10, 10))), new KeyValuePair <ushort, GeoPoint>(3, f.CreatePoint(new Coordinate(10, -10))), new KeyValuePair <ushort, GeoPoint>(4, f.CreatePoint(new Coordinate(0, 0))), }); _matrix[0, 1] = 10; _matrix[0, 2] = 5; _matrix[0, 3] = 10; _matrix[1, (ushort)0] = 10; _matrix[1, 2] = 10; _matrix[1, 3] = 5; _matrix[2, (ushort)0] = 5; _matrix[2, 1] = 10; _matrix[2, 3] = 10; _matrix[3, (ushort)0] = 10; _matrix[3, 1] = 5; _matrix[3, 2] = 10; _matrix[4, 4] = 15; }
protected MatrixProviderBase(IODMatrix matrix) { Factory = new NetTopologySuite.Geometries.GeometryFactory(); Matrix = matrix; MinValid = 0f; MaxValid = double.MaxValue; }
public void Multipg() { var rnd = new Random(); var pg = new Polygon[50]; var pgcheck = new GeoAPI.Geometries.IPolygon[50]; var gf = new NetTopologySuite.Geometries.GeometryFactory(); for (var i = 0; i < 50; i++) { var center = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90); var coord = new Coordinate[36]; var coordscheck = new GeoAPI.Geometries.Coordinate[36]; for (var 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); var x = coord[ii].X; var y = coord[ii].Y; var c = new GeoAPI.Geometries.Coordinate(x, y); coordscheck[ii] = c; } coord[35] = new Coordinate(coord[0].X, coord[0].Y); coordscheck[35] = new GeoAPI.Geometries.Coordinate(coordscheck[0].X, coordscheck[0].Y); var ring = gf.CreateLinearRing(coordscheck); pgcheck[i] = gf.CreatePolygon(ring, null); pg[i] = new Polygon(coord); } var mpg = new MultiPolygon(pg); var mpgcheck = gf.CreateMultiPolygon(pgcheck); for (var 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 SharpMap.Geometries.MultiLineString SplitLineString( SharpMap.Geometries.LineString lineString, System.Double length) { if (lineString == null || lineString.IsEmpty()) { throw new System.ArgumentException("Linestring is null or Empty", "lineString"); } var gf = new NetTopologySuite.Geometries.GeometryFactory(); var ntsLine = (NetTopologySuite.Geometries.LineString) SharpMap.Converters.NTS.GeometryConverter.ToNTSGeometry(lineString, gf); var ret = new SharpMap.Geometries.MultiLineString(); var lil = new NetTopologySuite.LinearReferencing.LengthIndexedLine(ntsLine); double currentLength = 0d; while (currentLength < ntsLine.Length) { var tmpLine = (NetTopologySuite.Geometries.LineString) lil.ExtractLine(currentLength, currentLength + length); ret.LineStrings.Add((SharpMap.Geometries.LineString) SharpMap.Converters.NTS.GeometryConverter.ToSharpMapGeometry(tmpLine)); currentLength += length; } return(ret); }
public void EnveloptMls() { var rnd = new Random(); var ls = new LineString[40]; var lscheck = new GeoAPI.Geometries.ILineString[40]; var gf = new NetTopologySuite.Geometries.GeometryFactory(); for (var ii = 0; ii < 40; ii++) { var coord = new Coordinate[36]; var coordcheck = new GeoAPI.Geometries.Coordinate[36]; for (var i = 0; i < 36; i++) { coord[i] = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90); var x = coord[i].X; var y = coord[i].Y; var c = new GeoAPI.Geometries.Coordinate(x, y); coordcheck[i] = c; } ls[ii] = new LineString(coord); lscheck[ii] = gf.CreateLineString(coordcheck); } var mls = new MultiLineString(ls); var mlscheck = gf.CreateMultiLineString(lscheck); Assert.AreEqual(mls.Envelope.Width, mlscheck.EnvelopeInternal.Width); Assert.AreEqual(mls.Envelope.Height, mlscheck.EnvelopeInternal.Height); }
public void Overlaps() { var rnd = new Random(); var pg = new Polygon[50]; var pgcheck = new GeoAPI.Geometries.IPolygon[50]; var gf = new NetTopologySuite.Geometries.GeometryFactory(); var center = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90); for (var i = 0; i < 50; i++) { var coord = new Coordinate[36]; var coordscheck = new GeoAPI.Geometries.Coordinate[36]; for (var 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); var x = coord[ii].X; var y = coord[ii].Y; var c = new GeoAPI.Geometries.Coordinate(x, y); coordscheck[ii] = c; } coord[35] = new Coordinate(coord[0].X, coord[0].Y); coordscheck[35] = new GeoAPI.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 (var t = 0; t < 49; t++) { var g = pg[t].Overlaps(pg[t + 1]); var gcheck = pgcheck[t].Overlaps(pgcheck[t + 1]); Assert.AreEqual(g, gcheck); } }
public void TestXml1() { var xml = @"<?xml version=""1.0"" encoding=""utf-8"" ?> <root> <Points> <Point> <X>13457786.5961983</X> <Y>1629064.58490612</Y> </Point> </Points> </root>"; var xmlFileName = System.IO.Path.ChangeExtension(System.IO.Path.GetTempFileName(), "xml"); using (var sw = new System.IO.StreamWriter(System.IO.File.OpenWrite(xmlFileName))) sw.Write(xml); var factory = new NetTopologySuite.Geometries.GeometryFactory(); SharpMap.Data.Providers.FeatureProvider p = null; using (var fs = System.IO.File.OpenRead(xmlFileName)) { p = new SharpMap.Data.Providers.FeatureProvider(PointsFromXml(factory, fs)); NUnit.Framework.Assert.IsNotNull(p); NUnit.Framework.Assert.AreEqual(1, p.Features.Count); } System.IO.File.Delete(xmlFileName); }
private void CreateMatrix() { var f = new NetTopologySuite.Geometries.GeometryFactory(); _matrix = new ODMatrix(new[] { new KeyValuePair<ushort, GeoPoint>(0, f.CreatePoint(new Coordinate(-10, -10))), new KeyValuePair<ushort, GeoPoint>(1, f.CreatePoint(new Coordinate(-10, 10))), new KeyValuePair<ushort, GeoPoint>(2, f.CreatePoint(new Coordinate(10, 10))), new KeyValuePair<ushort, GeoPoint>(3, f.CreatePoint(new Coordinate(10, -10))), new KeyValuePair<ushort, GeoPoint>(4, f.CreatePoint(new Coordinate(0, 0))), }); _matrix[0, 1] = 10; _matrix[0, 2] = 5; _matrix[0, 3] = 10; _matrix[1, (ushort)0] = 10; _matrix[1, 2] = 10; _matrix[1, 3] = 5; _matrix[2, (ushort)0] = 5; _matrix[2, 1] = 10; _matrix[2, 3] = 10; _matrix[3, (ushort)0] = 10; _matrix[3, 1] = 5; _matrix[3, 2] = 10; _matrix[4, 4] = 15; }
public void TestXml1() { var xml = @"<?xml version=""1.0"" encoding=""utf-8"" ?> <root> <Points> <Point> <X>13457786.5961983</X> <Y>1629064.58490612</Y> </Point> </Points> </root>"; var xmlFileName = System.IO.Path.ChangeExtension(System.IO.Path.GetTempFileName(), "xml"); using (var sw = new System.IO.StreamWriter(System.IO.File.OpenWrite(xmlFileName))) sw.Write(xml); var factory = new NetTopologySuite.Geometries.GeometryFactory(); SharpMap.Data.Providers.GeometryProvider p = null; using (var fs = System.IO.File.OpenRead(xmlFileName)) { p = new SharpMap.Data.Providers.GeometryProvider(PointsFromXml(factory, fs)); NUnit.Framework.Assert.IsNotNull(p); NUnit.Framework.Assert.AreEqual(1, p.Geometries.Count); } System.IO.File.Delete(xmlFileName); }
public static void EnsureVisible(SharpMap.Map map, SharpMap.Geometries.Point pt) { const double ensureVisibleRatio = 0.1d; //Get current map envelope var bb = map.Envelope; System.Console.WriteLine(string.Format("Map envelope: {0}", bb)); //Set valid envelope var evbb = bb.Grow(-ensureVisibleRatio * bb.Width, -ensureVisibleRatio * bb.Height); System.Console.WriteLine(string.Format("Valid envelope: {0}", evbb)); //Test if Point is in valid envelope if (evbb.Contains(pt)) { return; } //It is not System.Console.WriteLine(string.Format("Valid envelope does not contain {0}", pt)); //LineString from Map.Center -> to Point var ls = new SharpMap.Geometries.LineString(new[] { evbb.GetCentroid(), pt }); System.Console.WriteLine(string.Format("LineString Map.Center -> Point: {0}", ls)); //Setup Linestring from BoundingBox var gf = new NetTopologySuite.Geometries.GeometryFactory(); var evbbpts = new System.Collections.Generic.List <SharpMap.Geometries.Point>( new[] { evbb.TopLeft, evbb.TopRight, evbb.BottomRight, evbb.BottomLeft, evbb.TopLeft }); var evbblinearring = new SharpMap.Geometries.LineString(evbbpts); System.Console.WriteLine(string.Format("Linestring of valid envelope: {0}", evbblinearring)); // convert geometries to NTS var ntsevbb = (NetTopologySuite.Geometries.LineString) SharpMap.Converters.NTS.GeometryConverter.ToNTSGeometry(evbblinearring, gf); var ntsls = (NetTopologySuite.Geometries.LineString) SharpMap.Converters.NTS.GeometryConverter.ToNTSGeometry(ls, gf); // Get intersection point var intGeo = ntsevbb.Intersection(ntsls); var intPt = (NetTopologySuite.Geometries.Point)intGeo; System.Console.WriteLine(string.Format("Intersection point is: {0}", intPt)); //Compute offset var dx = pt.X - intPt.X; var dy = pt.Y - intPt.Y; System.Console.WriteLine(string.Format("Map.Center needs to be shifted by: [{0}, {1}]", dx, dy)); //Set new center Center map.Center = new SharpMap.Geometries.Point(map.Center.X + dx, map.Center.Y + dy); }
public void PolygonHoles() { var coords = new Coordinate[20]; var rnd = new Random(); var center = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90); // Shell Coordinates var coordscheck = new GeoAPI.Geometries.Coordinate[20]; for (var i = 0; i < 19; i++) { var x = center.X + Math.Cos((i * 10) * Math.PI / 10); var y = center.Y + (i * 10) * Math.PI / 10; coords[i] = new Coordinate(x, y); coordscheck[i] = new GeoAPI.Geometries.Coordinate(x, y); } coordscheck[19] = new GeoAPI.Geometries.Coordinate(coords[0].X, coords[0].Y); coords[19] = new Coordinate(coords[0].X, coords[0].Y); // Shell Rings var ring = new LinearRing(coords); var gf = new NetTopologySuite.Geometries.GeometryFactory(); var ringCheck = gf.CreateLinearRing(coordscheck); // Hole Coordinates var coordsholecheck = new GeoAPI.Geometries.Coordinate[20]; var coordshole = new Coordinate[20]; for (var i = 0; i < 20; i++) { var x = center.X + Math.Cos((i * 10) * Math.PI / 20); var y = center.Y + (i * 10) * Math.PI / 20; coordshole[i] = new Coordinate(x, y); coordsholecheck[i] = new GeoAPI.Geometries.Coordinate(x, y); } coordshole[19] = new Coordinate(coordshole[0].X, coordshole[0].Y); coordsholecheck[19] = new GeoAPI.Geometries.Coordinate(coordshole[0].X, coordshole[0].Y); // Hole LinearRing Arrays var hole = new LinearRing(coordshole); var holes = new ILinearRing[1]; var holeCheck = gf.CreateLinearRing(coordsholecheck); var holescheck = new GeoAPI.Geometries.ILinearRing[1]; holes[0] = hole; holescheck[0] = holeCheck; var pg = new Polygon(ring, holes); var polygonCheck = gf.CreatePolygon(ringCheck, holescheck); var areaCheck = polygonCheck.Area; var area = pg.Area; Assert.IsTrue(Math.Abs(area - areaCheck) < 1e-6); }
public void TestLengthIndexedLine() { var gf = new NetTopologySuite.Geometries.GeometryFactory(); var l = gf.CreateLineString( new [] { new GeoAPI.Geometries.Coordinate(0, 0), new GeoAPI.Geometries.Coordinate(300, 100),}); System.Console.WriteLine(SplitLineString(l, 20d)); }
public void TestLengthIndexedLine() { var gf = new NetTopologySuite.Geometries.GeometryFactory(); var l = gf.CreateLineString( new [] { new GeoAPI.Geometries.Coordinate(0, 0), new GeoAPI.Geometries.Coordinate(300, 100), }); System.Console.WriteLine(SplitLineString(l, 20d)); }
/// <summary> /// Creates a FeatureDataTable from arrays of x, y and z components /// </summary> /// <param name="xcomponents">an array of doubles representing the x ordinate values</param> /// <param name="ycomponents">an array of doubles representing the y ordinate values</param> /// <param name="zcomponents">an array of doubles representing the z ordinate values</param> /// <returns></returns> public static SharpMap.Data.FeatureDataTable CreatePointFeatureDataTableFromArrays(double[] xcomponents, double[] ycomponents, double[] zcomponents, double[] data = null) { var factory = new NetTopologySuite.Geometries.GeometryFactory(); var threedee = false; if (zcomponents != null) { if (!(zcomponents.Length == ycomponents.Length && zcomponents.Length == xcomponents.Length)) { throw new System.ApplicationException("Mismatched Array Lengths"); } threedee = true; } else { if (ycomponents.Length != xcomponents.Length) { throw new System.ApplicationException("Mismatched Array Lengths"); } } var fdt = new SharpMap.Data.FeatureDataTable(); fdt.Columns.Add("TimeStamp", typeof(System.DateTime)); // add example timestamp attribute if (data != null) { fdt.Columns.Add("Data", typeof(System.Double)); // add example timestamp attribute } for (var i = 0; i < xcomponents.Length; i++) { SharpMap.Data.FeatureDataRow fdr = fdt.NewRow(); fdr.Geometry = factory.CreatePoint(threedee ? new GeoAPI.Geometries.Coordinate(xcomponents[i], ycomponents[i], zcomponents[i]) : new GeoAPI.Geometries.Coordinate(xcomponents[i], ycomponents[i])); fdr["TimeStamp"] = System.DateTime.Now; //set the timestamp property if (data != null) { fdr["Data"] = data[i]; } fdt.AddRow(fdr); } return(fdt); }
public static void EnsureVisible(SharpMap.Map map, SharpMap.Geometries.Point pt) { const double ensureVisibleRatio = 0.1d; //Get current map envelope var bb = map.Envelope; System.Console.WriteLine(string.Format("Map envelope: {0}", bb)); //Set valid envelope var evbb = bb.Grow(- ensureVisibleRatio * bb.Width, -ensureVisibleRatio * bb.Height ); System.Console.WriteLine(string.Format("Valid envelope: {0}", evbb)); //Test if Point is in valid envelope if (evbb.Contains(pt)) return; //It is not System.Console.WriteLine(string.Format("Valid envelope does not contain {0}", pt)); //LineString from Map.Center -> to Point var ls = new SharpMap.Geometries.LineString(new[] {evbb.GetCentroid(), pt}); System.Console.WriteLine(string.Format("LineString Map.Center -> Point: {0}", ls)); //Setup Linestring from BoundingBox var gf = new NetTopologySuite.Geometries.GeometryFactory(); var evbbpts = new System.Collections.Generic.List<SharpMap.Geometries.Point>( new[] {evbb.TopLeft, evbb.TopRight, evbb.BottomRight, evbb.BottomLeft, evbb.TopLeft }); var evbblinearring = new SharpMap.Geometries.LineString(evbbpts); System.Console.WriteLine(string.Format("Linestring of valid envelope: {0}", evbblinearring)); // convert geometries to NTS var ntsevbb = (NetTopologySuite.Geometries.LineString) SharpMap.Converters.NTS.GeometryConverter.ToNTSGeometry(evbblinearring, gf); var ntsls = (NetTopologySuite.Geometries.LineString) SharpMap.Converters.NTS.GeometryConverter.ToNTSGeometry(ls, gf); // Get intersection point var intGeo = ntsevbb.Intersection(ntsls); var intPt = (NetTopologySuite.Geometries.Point)intGeo; System.Console.WriteLine(string.Format("Intersection point is: {0}", intPt)); //Compute offset var dx = pt.X - intPt.X; var dy = pt.Y - intPt.Y; System.Console.WriteLine(string.Format("Map.Center needs to be shifted by: [{0}, {1}]", dx, dy)); //Set new center Center map.Center = new SharpMap.Geometries.Point(map.Center.X + dx, map.Center.Y + dy); }
public void Buffer() { var rnd = new Random(); var coords = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90); var x = coords.X; var y = coords.Y; var c = new GeoAPI.Geometries.Coordinate(x, y); //coordscheck[i] = c; var p = new Point(coords); var gf = new NetTopologySuite.Geometries.GeometryFactory(); var ps = gf.CreatePoint(c); var area = p.Buffer(500).Area; var areacheck = ps.Buffer(500).Area; Assert.IsTrue(Math.Abs(area - areacheck) < 1e-6); }
public void BufferLength() { var rnd = new Random(); var coords = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90); var x = coords.X; var y = coords.Y; var c = new GeoAPI.Geometries.Coordinate(x, y); //coordscheck[i] = c; var p = new Point(coords); var gf = new NetTopologySuite.Geometries.GeometryFactory(); var ps = gf.CreatePoint(c); var boundary = p.Buffer(500).Length; var boundarycheck = ps.Buffer(500).Length; AssertExt.AreEqual15(boundary, boundarycheck); }
/// <summary> /// Creates an instance of this class /// </summary> /// <param name="layername">The layer name</param> /// <param name="provider">The provider</param> public AnimatedGifLayer(string layername, IProvider provider) { var rs = Assembly.GetExecutingAssembly().GetManifestResourceStream("SharpMap.Layers.GreenDot.gif"); if (rs != null) { _animatedGif = Image.FromStream(rs); //rs.Dispose(); } LayerName = layername; _provider = provider; SourceFactory = new NetTopologySuite.Geometries.GeometryFactory( NetTopologySuite.Geometries.GeometryFactory.Default.PrecisionModel, _provider.SRID, NetTopologySuite.Geometries.GeometryFactory.Default.CoordinateSequenceFactory); _pictureBoxes = new Dictionary <uint, PictureBox>(); }
public void LineStringCoordiantesCount() { var coords = new Coordinate[36]; var rnd = new Random(); var coordscheck = new GeoAPI.Geometries.Coordinate[36]; for (var i = 0; i < 36; i++) { coords[i] = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90); var x = coords[i].X; var y = coords[i].Y; var c = new GeoAPI.Geometries.Coordinate(x, y); coordscheck[i] = c; } var gf = new NetTopologySuite.Geometries.GeometryFactory(); var lscheck = gf.CreateLineString(coordscheck); var ls = new LineString(coords); Assert.AreEqual(ls.Coordinates.Count, lscheck.Coordinates.Count()); }
public void LineLength() { var coords = new Coordinate[36]; var rnd = new Random(); var coordscheck = new GeoAPI.Geometries.Coordinate[36]; for (var i = 0; i < 36; i++) { coords[i] = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90); var x = coords[i].X; var y = coords[i].Y; var c = new GeoAPI.Geometries.Coordinate(x, y); coordscheck[i] = c; } var gf = new NetTopologySuite.Geometries.GeometryFactory(); var lscheck = gf.CreateLineString(coordscheck); var ls = new LineString(coords); var length = ls.Length; var lengthcheck = lscheck.Length; Assert.AreEqual(length, lengthcheck); }
public void LineStringEnvelopeHeightWidth() { var coords = new Coordinate[36]; var rnd = new Random(); var coordscheck = new GeoAPI.Geometries.Coordinate[36]; for (var i = 0; i < 36; i++) { coords[i] = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90); var x = coords[i].X; var y = coords[i].Y; var c = new GeoAPI.Geometries.Coordinate(x, y); coordscheck[i] = c; } var gf = new NetTopologySuite.Geometries.GeometryFactory(); GeoAPI.Geometries.ILineString lscheck = gf.CreateLineString(coordscheck); var ls = new LineString(coords); AssertExt.AreEqual15(ls.Envelope.Width, lscheck.EnvelopeInternal.Width); AssertExt.AreEqual15(ls.Envelope.Height, lscheck.EnvelopeInternal.Height); }
public void Intersection() { var rnd = new Random(); var pg = new Polygon[50]; var pgcheck = new GeoAPI.Geometries.IPolygon[50]; var gf = new NetTopologySuite.Geometries.GeometryFactory(); var center = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90); for (var i = 0; i < 50; i++) { var coord = new Coordinate[36]; var coordscheck = new GeoAPI.Geometries.Coordinate[36]; for (var 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); var x = coord[ii].X; var y = coord[ii].Y; var c = new GeoAPI.Geometries.Coordinate(x, y); coordscheck[ii] = c; } coord[35] = new Coordinate(coord[0].X, coord[0].Y); coordscheck[35] = new GeoAPI.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 (var t = 0; t < 49; t++) { var g = pg[t].Intersection(pg[t + 1]); var gcheck = pgcheck[t].Intersection(pgcheck[t + 1]); for (var 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 MpsBufferArea() { 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); var area = mps.Buffer(500).Area; var areacheck = mpsCheck.Buffer(500).Area; Assert.IsTrue(Math.Abs(area - areacheck) < 1e-6); }
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); } }
public void PolygonShellEndPoint() { var coords = new Coordinate[20]; var rnd = new Random(); var center = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90); var coordscheck = new GeoAPI.Geometries.Coordinate[20]; for (var 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); var x = coords[i].X; var y = coords[i].Y; var c = new GeoAPI.Geometries.Coordinate(x, y); coordscheck[i] = c; } coordscheck[19] = new GeoAPI.Geometries.Coordinate(coords[0].X, coords[0].Y); coords[19] = new Coordinate(coords[0].X, coords[0].Y); var gf = new NetTopologySuite.Geometries.GeometryFactory(); var ring = gf.CreateLinearRing(coordscheck); var polygonCheck = gf.CreatePolygon(ring, null); var pg = new Polygon(coords); AssertExt.AreEqual15(pg.Shell.EndPoint.X, polygonCheck.Shell.EndPoint.X); AssertExt.AreEqual15(pg.Shell.EndPoint.Y, polygonCheck.Shell.EndPoint.Y); }
public static void TestUnion() { string s1 = "POLYGON((8.3038582 47.0506309,8.3038611 47.050588,8.3038772 47.0504833,8.3041581 47.0505083,8.3041532 47.0506229,8.303965 47.0506089,8.3039616 47.0506342,8.3038582 47.0506309))"; string s2 = "POLYGON((8.3041532 47.0506229,8.3041581 47.0505083,8.3042898 47.0505392,8.3042879 47.050571,8.3042854 47.0506139,8.3041532 47.0506229))"; string s3 = "POLYGON((8.3042879 47.050571,8.30442 47.05058,8.3044327 47.0507439,8.3043001 47.0507637,8.3042885 47.0506777,8.3042854 47.0506139,8.3042879 47.050571))"; string s4 = "POLYGON((8.304174 47.050784,8.3041695 47.0507507,8.3041592 47.0506835,8.3041585 47.0506448,8.3042166 47.0506438,8.3042225 47.0506777,8.3042885 47.0506777,8.3043001 47.0507637,8.304174 47.050784))"; Wgs84Coordinates[] coords1 = PolygonParsingExtensions.PolygonStringToCoordinates(s1); Wgs84Coordinates[] coords2 = PolygonParsingExtensions.PolygonStringToCoordinates(s2); Wgs84Coordinates[] coords3 = PolygonParsingExtensions.PolygonStringToCoordinates(s3); Wgs84Coordinates[] coords4 = PolygonParsingExtensions.PolygonStringToCoordinates(s4); NetTopologySuite.Geometries.GeometryFactory geomFactory = new NetTopologySuite.Geometries.GeometryFactory(); GeoAPI.Geometries.IPolygon poly1 = geomFactory.CreatePolygon(coords1.ToNetTopologyCoordinates()); GeoAPI.Geometries.IPolygon poly2 = geomFactory.CreatePolygon(coords2.ToNetTopologyCoordinates()); GeoAPI.Geometries.IPolygon poly3 = geomFactory.CreatePolygon(coords3.ToNetTopologyCoordinates()); GeoAPI.Geometries.IPolygon poly4 = geomFactory.CreatePolygon(coords4.ToNetTopologyCoordinates()); System.Collections.Generic.List <GeoAPI.Geometries.IGeometry> lsPolygons = new System.Collections.Generic.List <GeoAPI.Geometries.IGeometry>(); lsPolygons.Add(poly1); lsPolygons.Add(poly2); lsPolygons.Add(poly3); lsPolygons.Add(poly4); GeoAPI.Geometries.IGeometry ig = NetTopologySuite.Operation.Union.CascadedPolygonUnion.Union(lsPolygons); System.Console.WriteLine(ig.GetType().FullName); GeoAPI.Geometries.IPolygon unionPolygon = (GeoAPI.Geometries.IPolygon)ig; System.Console.WriteLine(poly3); System.Console.WriteLine(unionPolygon.Shell.Coordinates); System.Collections.Generic.List <Wgs84Coordinates> coords = new System.Collections.Generic.List <Wgs84Coordinates>(); for (int i = 0; i < unionPolygon.Shell.Coordinates.Length; ++i) { coords.Add(new Wgs84Coordinates(unionPolygon.Shell.Coordinates[i].X, unionPolygon.Shell.Coordinates[i].Y)); } coords = PolygonParsingExtensions.ToCounterClockWise(coords); // Close polygon if unclosed if (coords[0].Latitude != coords[coords.Count - 1].Latitude || coords[0].Longitude != coords[coords.Count - 1].Longitude) { coords.Add(coords[0]); } string insertString = @" DECLARE @GB_UID AS uniqueidentifier; DECLARE @SO_UID AS uniqueidentifier; SET @GB_UID = NULLIF('abc', ''); SET @SO_UID = NULLIF('', ''); DELETE FROM T_ZO_Objekt_Wgs84Polygon WHERE ZO_OBJ_WGS84_GB_UID = @GB_UID; /* INSERT INTO T_ZO_Objekt_Wgs84Polygon ( ZO_OBJ_WGS84_UID ,ZO_OBJ_WGS84_GB_UID ,ZO_OBJ_WGS84_SO_UID ,ZO_OBJ_WGS84_Sort ,ZO_OBJ_WGS84_GM_Lat ,ZO_OBJ_WGS84_GM_Lng ) */"; for (int i = 0; i < coords.Count; ++i) { if (i != 0) { insertString += " \r\n\r\n\r\nUNION ALL \r\n\r\n"; } insertString += $@" SELECT NEWID() AS ZO_OBJ_WGS84_UID ,CAST(@GB_UID AS uniqueidentifier) AS ZO_OBJ_WGS84_GB_UID ,CAST(@SO_UID AS uniqueidentifier) AS ZO_OBJ_WGS84_SO_UID ,CAST({i.ToString(System.Globalization.CultureInfo.InvariantCulture)} AS integer) + 1 AS ZO_OBJ_WGS84_Sort ,{coords[i].Latitude.ToString(System.Globalization.CultureInfo.InvariantCulture)} AS ZO_OBJ_WGS84_GM_Lat -- decimal(23, 20) ,{coords[i].Longitude.ToString(System.Globalization.CultureInfo.InvariantCulture)} AS ZO_OBJ_WGS84_GM_Lng -- decimal(23, 20) "; } insertString += " \r\n; \r\n\r\n"; System.Console.WriteLine(insertString); System.Console.WriteLine("--- Press any key to continue --- "); System.Console.ReadKey(); }
static RelationProvider() { Factory = new NetTopologySuite.Geometries.GeometryFactory(); }
/// <summary> /// Generate a query for the specified 'filter'. /// </summary> /// <param name="context"></param> /// <param name="user"></param> /// <param name="filter"></param> /// <returns></returns> public static IQueryable <Entity.Views.Property> GenerateQuery(this PimsContext context, ClaimsPrincipal user, Entity.Models.AllPropertyFilter filter) { filter.ThrowIfNull(nameof(filter)); filter.ThrowIfNull(nameof(user)); // Check if user has the ability to view sensitive properties. var userAgencies = user.GetAgenciesAsNullable(); var viewSensitive = user.HasPermission(Permissions.SensitiveView); var isAdmin = user.HasPermission(Permissions.AdminProperties); // Users may only view sensitive properties if they have the `sensitive-view` claim and belong to the owning agency. var query = context.Properties .AsNoTracking() .Where(p => p.ClassificationId != 4); // Disposed properties are not visible. // Only allowed to see user's own agency properties. if (!isAdmin) { query = query.Where(p => p.IsVisibleToOtherAgencies || userAgencies.Contains(p.AgencyId)); } if (!viewSensitive) { query = query.Where(p => !p.IsSensitive); } if (filter.PropertyType.HasValue) { query = query.Where(p => p.PropertyTypeId == filter.PropertyType); } if (filter.NELatitude.HasValue && filter.NELongitude.HasValue && filter.SWLatitude.HasValue && filter.SWLongitude.HasValue) { var pfactory = new NetTopologySuite.Geometries.GeometryFactory(); var ring = new NetTopologySuite.Geometries.LinearRing( new[] { new NetTopologySuite.Geometries.Coordinate(filter.NELongitude.Value, filter.NELatitude.Value), new NetTopologySuite.Geometries.Coordinate(filter.SWLongitude.Value, filter.NELatitude.Value), new NetTopologySuite.Geometries.Coordinate(filter.SWLongitude.Value, filter.SWLatitude.Value), new NetTopologySuite.Geometries.Coordinate(filter.NELongitude.Value, filter.SWLatitude.Value), new NetTopologySuite.Geometries.Coordinate(filter.NELongitude.Value, filter.NELatitude.Value) }); var poly = pfactory.CreatePolygon(ring); poly.SRID = 4326; query = query.Where(p => poly.Contains(p.Location)); } if (filter.Agencies?.Any() == true) { // Get list of sub-agencies for any agency selected in the filter. var filterAgencies = filter.Agencies.Select(a => (int?)a); var agencies = filterAgencies.Concat(context.Agencies.AsNoTracking().Where(a => filterAgencies.Contains(a.Id)).SelectMany(a => a.Children.Select(ac => (int?)ac.Id)).ToArray()).Distinct(); query = query.Where(p => agencies.Contains(p.AgencyId)); } if (filter.ParcelId.HasValue) { query = query.Where(p => p.ParcelId == filter.ParcelId); } if (filter.ClassificationId.HasValue) { query = query.Where(p => p.ClassificationId == filter.ClassificationId); } if (!String.IsNullOrWhiteSpace(filter.ProjectNumber)) { query = query.Where(p => EF.Functions.Like(p.ProjectNumber, $"{filter.ProjectNumber}%")); } if (filter.IgnorePropertiesInProjects == true) { query = query.Where(p => p.ProjectNumber == null); } if (filter.InSurplusPropertyProgram == true) { query = query.Where(p => !String.IsNullOrWhiteSpace(p.ProjectNumber)); } if (!String.IsNullOrWhiteSpace(filter.Description)) { query = query.Where(p => EF.Functions.Like(p.Description, $"%{filter.Description}%")); } if (!String.IsNullOrWhiteSpace(filter.PID)) { var pidValue = filter.PID.Replace("-", "").Trim(); if (Int32.TryParse(pidValue, out int pid)) { query = query.Where(p => p.PID == pid || p.PIN == pid); } } if (!String.IsNullOrWhiteSpace(filter.AdministrativeArea)) { query = query.Where(p => EF.Functions.Like(p.AdministrativeArea, $"%{filter.AdministrativeArea}%")); } if (!String.IsNullOrWhiteSpace(filter.Zoning)) { query = query.Where(p => EF.Functions.Like(p.Zoning, $"%{filter.Zoning}%")); } if (!String.IsNullOrWhiteSpace(filter.ZoningPotential)) { query = query.Where(p => EF.Functions.Like(p.ZoningPotential, $"%{filter.ZoningPotential}%")); } if (filter.ConstructionTypeId.HasValue) { query = query.Where(p => p.BuildingConstructionTypeId == filter.ConstructionTypeId); } if (filter.PredominateUseId.HasValue) { query = query.Where(p => p.BuildingPredominateUseId == filter.PredominateUseId); } if (filter.FloorCount.HasValue) { query = query.Where(p => p.BuildingFloorCount == filter.FloorCount); } if (!String.IsNullOrWhiteSpace(filter.Tenancy)) { query = query.Where(p => EF.Functions.Like(p.BuildingTenancy, $"%{filter.Tenancy}%")); } if (!String.IsNullOrWhiteSpace(filter.Address)) { query = query.Where(p => EF.Functions.Like(p.Address, $"%{filter.Address}%") || EF.Functions.Like(p.AdministrativeArea, $"%{filter.Address}%")); } if (filter.MinLandArea.HasValue) { query = query.Where(p => p.LandArea >= filter.MinLandArea); } if (filter.MaxLandArea.HasValue) { query = query.Where(b => b.LandArea <= filter.MaxLandArea); } if (filter.MinRentableArea.HasValue) { query = query.Where(p => p.RentableArea >= filter.MinRentableArea); } if (filter.MaxRentableArea.HasValue) { query = query.Where(b => b.RentableArea <= filter.MaxRentableArea); } if (filter.MinEstimatedValue.HasValue) { query = query.Where(p => p.Estimated >= filter.MinEstimatedValue); } if (filter.MaxEstimatedValue.HasValue) { query = query.Where(p => p.Estimated <= filter.MaxEstimatedValue); } if (filter.MinAssessedValue.HasValue) { query = query.Where(p => p.Assessed >= filter.MinAssessedValue); } if (filter.MaxAssessedValue.HasValue) { query = query.Where(p => p.Assessed <= filter.MaxAssessedValue); } if (filter.InEnhancedReferralProcess.HasValue && filter.InEnhancedReferralProcess.Value) { var statuses = context.Workflows.Where(w => w.Code == "ERP") .SelectMany(w => w.Status).Where(x => !x.Status.IsTerminal) .Select(x => x.StatusId).Distinct().ToArray(); query = query.Where(property => context.Projects.Any(project => statuses.Any(st => st == project.StatusId) && project.ProjectNumber == property.ProjectNumber)); } if (filter.Sort?.Any() == true) { query = query.OrderByProperty(filter.Sort); } else { query = query.OrderBy(p => p.AgencyCode).ThenBy(p => p.PID).ThenBy(p => p.PIN).ThenBy(p => p.PropertyTypeId); } return(query); }
public static void Test() { string s1 = "POLYGON((7.5999034 47.5506347,7.5997595 47.5507183,7.5998959 47.5508256,7.5999759 47.5508885,7.6001195 47.550805,7.5999034 47.5506347))"; string s2 = "POLYGON((7.6003356 47.5509754,7.6001195 47.550805,7.5999759 47.5508885,7.6000322 47.5509328,7.6001926 47.551059,7.6003356 47.5509754))"; s1 = "POLYGON((7.5999034 47.5506347,7.6001195 47.550805,7.5999759 47.5508885,7.5998959 47.5508256,7.5997595 47.5507183,7.5999034 47.5506347))"; s2 = "POLYGON((7.6003356 47.5509754,7.6001926 47.551059,7.6000322 47.5509328,7.5999759 47.5508885,7.6001195 47.550805,7.6003356 47.5509754))"; // NetTopologySuite.Geometries.Implementation.CoordinateArraySequenceFactory // GeoAPI.Geometries.IGeometryFactory geoFactory = new NetTopologySuite.Geometries.GeometryFactory(); NetTopologySuite.IO.WKTReader wr = new NetTopologySuite.IO.WKTReader(); Wgs84Coordinates[] coords1 = PolygonParsingExtensions.PolygonStringToCoordinates(s1); Wgs84Coordinates[] coords2 = PolygonParsingExtensions.PolygonStringToCoordinates(s2); var lr = new NetTopologySuite.Geometries.LinearRing(coords1.ToNetTopologyCoordinates()); System.Console.WriteLine(lr.IsValid); var x = new NetTopologySuite.Geometries.Polygon(new NetTopologySuite.Geometries.LinearRing(coords1.ToNetTopologyCoordinates())); System.Console.WriteLine(x.IsValid); NetTopologySuite.Geometries.GeometryFactory geomFactory = new NetTopologySuite.Geometries.GeometryFactory(); GeoAPI.Geometries.IPolygon poly1 = geomFactory.CreatePolygon(coords1.ToNetTopologyCoordinates()); GeoAPI.Geometries.IPolygon poly2 = geomFactory.CreatePolygon(coords2.ToNetTopologyCoordinates()); /* * GeoAPI.Geometries.IPolygon poly1 = (GeoAPI.Geometries.IPolygon)wr.Read(s1); * GeoAPI.Geometries.IPolygon poly2 = (GeoAPI.Geometries.IPolygon)wr.Read(s2); */ poly1.SRID = 4326; poly2.SRID = 4326; CalculateArea2(coords1); CalculateArea2(coords2); System.Console.WriteLine(poly1.Area); System.Console.WriteLine(poly2.Area); GeoAPI.Geometries.IPolygon poly3quick = (GeoAPI.Geometries.IPolygon)poly1.Union(poly2); System.Console.WriteLine(poly3quick.IsValid); // https://gis.stackexchange.com/questions/209797/how-to-get-geometry-points-using-geo-api System.Console.Write(poly1.IsValid); System.Console.Write(poly2.IsValid); System.Collections.Generic.List <GeoAPI.Geometries.IGeometry> lsPolygons = new System.Collections.Generic.List <GeoAPI.Geometries.IGeometry>(); lsPolygons.Add(poly1); lsPolygons.Add(poly2); GeoAPI.Geometries.IGeometry ig = NetTopologySuite.Operation.Union.CascadedPolygonUnion.Union(lsPolygons); System.Console.WriteLine(ig.GetType().FullName); GeoAPI.Geometries.IPolygon poly3 = (GeoAPI.Geometries.IPolygon)ig; System.Console.WriteLine(poly3); // POLYGON ((7.5997595 47.5507183, 7.5999034 47.5506347, 7.6001195 47.550805, 7.6003356 47.5509754 // , 7.6001926 47.551059, 7.6000322 47.5509328, 7.5999759 47.5508885 // , 7.5998959 47.5508256, 7.5997595 47.5507183)) System.Console.WriteLine(poly3.Shell.Coordinates); /* * // GeoAPI.Geometries.IPolygon poly3 = (GeoAPI.Geometries.IPolygon)ig; * NetTopologySuite.Geometries.MultiPolygon poly3a = (NetTopologySuite.Geometries.MultiPolygon)ig; * GeoAPI.Geometries.IGeometry ig2 = poly3a.ConvexHull(); * System.Console.WriteLine(ig2.GetType().FullName); */ // GeoAPI.Geometries.IPolygon poly4 = (GeoAPI.Geometries.IPolygon)ig2; // System.Console.WriteLine(poly4); System.Console.WriteLine("--- Press any key to continue --- "); System.Console.ReadKey(); } // End Sub Test
/// <summary> /// Generate a query for the specified 'filter'. /// </summary> /// <param name="context"></param> /// <param name="user"></param> /// <param name="filter"></param> /// <returns></returns> public static IQueryable <Entity.Parcel> GenerateQuery(this PimsContext context, ClaimsPrincipal user, Entity.Models.ParcelFilter filter) { filter.ThrowIfNull(nameof(user)); filter.ThrowIfNull(nameof(filter)); // Check if user has the ability to view sensitive properties. var userAgencies = user.GetAgenciesAsNullable(); var viewSensitive = user.HasPermission(Permissions.SensitiveView); var isAdmin = user.HasPermission(Permissions.AdminProperties); // Users may only view sensitive properties if they have the `sensitive-view` claim and belong to the owning agency. var query = context.Parcels.AsNoTracking(); if (!isAdmin) { query = query.Where(p => p.IsVisibleToOtherAgencies || ((!p.IsSensitive || viewSensitive) && userAgencies.Contains(p.AgencyId))); } if (filter.NELatitude.HasValue && filter.NELongitude.HasValue && filter.SWLatitude.HasValue && filter.SWLongitude.HasValue) { var pfactory = new NetTopologySuite.Geometries.GeometryFactory(); var ring = new NetTopologySuite.Geometries.LinearRing( new[] { new NetTopologySuite.Geometries.Coordinate(filter.NELongitude.Value, filter.NELatitude.Value), new NetTopologySuite.Geometries.Coordinate(filter.SWLongitude.Value, filter.NELatitude.Value), new NetTopologySuite.Geometries.Coordinate(filter.SWLongitude.Value, filter.SWLatitude.Value), new NetTopologySuite.Geometries.Coordinate(filter.NELongitude.Value, filter.SWLatitude.Value), new NetTopologySuite.Geometries.Coordinate(filter.NELongitude.Value, filter.NELatitude.Value) }); var poly = pfactory.CreatePolygon(ring); poly.SRID = 4326; query = query.Where(p => poly.Contains(p.Location)); } if (filter.Agencies?.Any() == true) { // Get list of sub-agencies for any agency selected in the filter. var filterAgencies = filter.Agencies.Select(a => (int?)a); var agencies = filterAgencies.Concat(context.Agencies.AsNoTracking().Where(a => filterAgencies.Contains(a.Id)).SelectMany(a => a.Children.Select(ac => (int?)ac.Id)).ToArray()).Distinct(); query = query.Where(p => agencies.Contains(p.AgencyId)); } if (filter.ClassificationId.HasValue) { query = query.Where(p => p.ClassificationId == filter.ClassificationId); } if (!String.IsNullOrWhiteSpace(filter.ProjectNumber)) { query = query.Where(p => EF.Functions.Like(p.ProjectNumber, $"{filter.ProjectNumber}%")); } if (!String.IsNullOrWhiteSpace(filter.Description)) { query = query.Where(p => EF.Functions.Like(p.Description, $"%{filter.Description}%")); } if (!String.IsNullOrWhiteSpace(filter.AdministrativeArea)) { query = query.Where(p => EF.Functions.Like(p.Address.AdministrativeArea, $"%{filter.AdministrativeArea}%")); } if (!String.IsNullOrWhiteSpace(filter.Zoning)) { query = query.Where(p => EF.Functions.Like(p.Zoning, $"%{filter.Zoning}%")); } if (!String.IsNullOrWhiteSpace(filter.ZoningPotential)) { query = query.Where(p => EF.Functions.Like(p.ZoningPotential, $"%{filter.ZoningPotential}%")); } // TODO: Parse the address information by City, Postal, etc. if (!String.IsNullOrWhiteSpace(filter.Address)) { query = query.Where(p => EF.Functions.Like(p.Address.Address1, $"%{filter.Address}%") || EF.Functions.Like(p.Address.AdministrativeArea, $"%{filter.Address}%")); } if (filter.MinLandArea.HasValue) { query = query.Where(p => p.LandArea >= filter.MinLandArea); } if (filter.MaxLandArea.HasValue) { query = query.Where(p => p.LandArea <= filter.MaxLandArea); } // TODO: Review performance of the evaluation query component. if (filter.MinEstimatedValue.HasValue) { query = query.Where(p => filter.MinEstimatedValue <= p.Fiscals .FirstOrDefault(e => e.FiscalYear == context.ParcelFiscals .Where(pe => pe.ParcelId == p.Id && pe.Key == Entity.FiscalKeys.Estimated) .Max(pe => pe.FiscalYear)) .Value); } if (filter.MaxEstimatedValue.HasValue) { query = query.Where(p => filter.MaxEstimatedValue >= p.Fiscals .FirstOrDefault(e => e.FiscalYear == context.ParcelFiscals .Where(pe => pe.ParcelId == p.Id && pe.Key == Entity.FiscalKeys.Estimated) .Max(pe => pe.FiscalYear)) .Value); } // TODO: Review performance of the evaluation query component. if (filter.MinAssessedValue.HasValue) { query = query.Where(p => filter.MinAssessedValue <= p.Evaluations .FirstOrDefault(e => e.Date == context.ParcelEvaluations .Where(pe => pe.ParcelId == p.Id && pe.Key == Entity.EvaluationKeys.Assessed) .Max(pe => pe.Date)) .Value); } if (filter.MaxAssessedValue.HasValue) { query = query.Where(p => filter.MaxAssessedValue >= p.Evaluations .FirstOrDefault(e => e.Date == context.ParcelEvaluations .Where(pe => pe.ParcelId == p.Id && pe.Key == Entity.EvaluationKeys.Assessed) .Max(pe => pe.Date)) .Value); } if (filter.Sort?.Any() == true) { query = query.OrderByProperty(filter.Sort); } else { query = query.OrderBy(p => p.Id); } return(query); }
public void PolygonEnvelopeMaxMin() { var coords = new Coordinate[20]; var rnd = new Random(); var center = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90); var coordscheck = new GeoAPI.Geometries.Coordinate[20]; for (var 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); var x = coords[i].X; var y = coords[i].Y; var c = new GeoAPI.Geometries.Coordinate(x, y); coordscheck[i] = c; } coordscheck[19] = new GeoAPI.Geometries.Coordinate(coords[0].X, coords[0].Y); coords[19] = new Coordinate(coords[0].X, coords[0].Y); var gf = new NetTopologySuite.Geometries.GeometryFactory(); GeoAPI.Geometries.ILinearRing ring = gf.CreateLinearRing(coordscheck); GeoAPI.Geometries.IPolygon pgcheck = gf.CreatePolygon(ring, null); var 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 MpsBufferArea() { 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); var area = mps.Buffer(500).Area; var areacheck = mpsCheck.Buffer(500).Area; Assert.IsTrue(Math.Abs(area - areacheck) < 1e-6 ); }
public void LineEndPoint() { var coords = new Coordinate[36]; var rnd = new Random(); var coordscheck = new GeoAPI.Geometries.Coordinate[36]; for (var i = 0; i < 36; i++) { coords[i] = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90); var x = coords[i].X; var y = coords[i].Y; var c = new GeoAPI.Geometries.Coordinate(x, y); coordscheck[i] = c; } var gf = new NetTopologySuite.Geometries.GeometryFactory(); var lscheck = gf.CreateLineString(coordscheck); var ls = new LineString(coords); AssertExt.AreEqual15(ls.EndPoint.X, lscheck.EndPoint.X); AssertExt.AreEqual15(ls.EndPoint.Y, lscheck.EndPoint.Y); }
/// <summary> /// Creates an instance of this class /// </summary> /// <param name="layername">The layer name</param> /// <param name="provider">The provider</param> public AnimatedGifLayer(string layername, IProvider provider) { var rs = Assembly.GetExecutingAssembly().GetManifestResourceStream("SharpMap.Layers.GreenDot.gif"); if (rs != null) { _animatedGif = Image.FromStream(rs); //rs.Dispose(); } LayerName = layername; _provider = provider; SourceFactory = new NetTopologySuite.Geometries.GeometryFactory( NetTopologySuite.Geometries.GeometryFactory.Default.PrecisionModel,_provider.SRID, NetTopologySuite.Geometries.GeometryFactory.Default.CoordinateSequenceFactory ); _pictureBoxes = new Dictionary<uint, PictureBox>(); }
/// <summary> /// Converts the given OsmSharp feature into an NTS feature. /// </summary> /// <param name="feature"></param> /// <returns></returns> public static Feature Convert(OsmSharp.Geo.Features.Feature feature) { if (feature == null) { throw new ArgumentNullException("feature"); } var geometryFactory = new NetTopologySuite.Geometries.GeometryFactory(); if(feature.Geometry is OsmSharp.Geo.Geometries.Polygon) { // a polygon. var polygon = (feature.Geometry as OsmSharp.Geo.Geometries.Polygon); var holes = polygon.Holes.Select((hole) => { return (ILinearRing)geometryFactory.CreateLinearRing(hole.Coordinates.Select((coordinate) => { return new Coordinate(coordinate.Longitude, coordinate.Latitude); }).ToArray()); }).ToArray(); var shell = geometryFactory.CreateLinearRing(polygon.Ring.Coordinates.Select((coordinate) => { return new Coordinate(coordinate.Longitude, coordinate.Latitude); }).ToArray()); return new Feature(geometryFactory.CreatePolygon(shell, holes), OsmSharpToNTSFeatureConvertor.Convert(feature.Attributes)); } else if (feature.Geometry is OsmSharp.Geo.Geometries.LineairRing) { // a lineair ring. var lineairRing = (feature.Geometry as OsmSharp.Geo.Geometries.LineairRing); var coordinates = lineairRing.Coordinates.Select((coordinate) => { return new Coordinate(coordinate.Longitude, coordinate.Latitude); }); return new Feature(geometryFactory.CreateLinearRing(coordinates.ToArray()), OsmSharpToNTSFeatureConvertor.Convert(feature.Attributes)); } else if (feature.Geometry is OsmSharp.Geo.Geometries.LineString) { // a line string. var lineString = (feature.Geometry as OsmSharp.Geo.Geometries.LineString); var coordinates = lineString.Coordinates.Select((coordinate) => { return new Coordinate(coordinate.Longitude, coordinate.Latitude); }); return new Feature(geometryFactory.CreateLineString(coordinates.ToArray()), OsmSharpToNTSFeatureConvertor.Convert(feature.Attributes)); } else if (feature.Geometry is OsmSharp.Geo.Geometries.Point) { // a point. var point = (feature.Geometry as OsmSharp.Geo.Geometries.Point); return new Feature(geometryFactory.CreatePoint(new Coordinate(point.Coordinate.Longitude, point.Coordinate.Latitude)), OsmSharpToNTSFeatureConvertor.Convert(feature.Attributes)); } else if (feature.Geometry is OsmSharp.Geo.Geometries.MultiLineString) { // a multi line string. throw new NotSupportedException("A MultiLineString is not supported."); } else if (feature.Geometry is OsmSharp.Geo.Geometries.MultiPoint) { // a multi point. throw new NotSupportedException("A MultiPoint is not supported."); } else if (feature.Geometry is OsmSharp.Geo.Geometries.MultiPolygon) { // a multi polygon. throw new NotSupportedException("A MultiPolygon is not supported."); } throw new ArgumentOutOfRangeException("Geometry not recognized: {0}", feature.ToString()); }