/// <summary> /// Find the nearest feature to worldPos out of a collection of candidates. If there is no geometry /// with a distance less than limit null is returned. /// </summary> /// <param name="candidates"></param> /// <param name="worldPos"></param> /// <param name="limit"></param> /// <param name="distance"></param> /// <returns></returns> private static IFeature FindNearestFeature(VectorLayer vectorLayer, IEnumerable candidates, ICoordinate worldPos, float limit, out double distance) { IPoint point = GeometryFactory.CreatePoint(worldPos.X, worldPos.Y); IFeature current = null; distance = double.MaxValue; foreach (IFeature feature in candidates) { IGeometry geometry; if (vectorLayer.CustomRenderers.Count > 0) { geometry = vectorLayer.CustomRenderers[0].GetRenderedFeatureGeometry(feature, vectorLayer); } else { if (vectorLayer.CoordinateTransformation != null) { geometry = GeometryTransform.TransformGeometry(feature.Geometry, vectorLayer.CoordinateTransformation.MathTransform); } else { geometry = feature.Geometry; } } double localDistance = geometry.Distance(point); if ((localDistance < distance) && (localDistance < limit)) { current = feature; distance = localDistance; } } return(current); }
public static Envelope ToSource(this Layer self, Envelope envelope) { #if !DotSpatialProjections if (self.ReverseCoordinateTransformation != null) { return(GeometryTransform.TransformBox(envelope, self.ReverseCoordinateTransformation.MathTransform)); } #endif if (self.CoordinateTransformation != null) { #if !DotSpatialProjections var mt = self.CoordinateTransformation.MathTransform; mt.Invert(); var res = GeometryTransform.TransformBox(envelope, mt); mt.Invert(); return(res); #else return(GeometryTransform.TransformBox(envelope, CoordinateTransformation.Target, CoordinateTransformation.Source)); #endif } // no transformation return(envelope); }
public static void Convert(string shapefile, string connectionString, string tableName, int srid = 0, string targetProjectionWKT = null) { GeometryTransform transform = GeometryTransform.GetTransform(shapefile, targetProjectionWKT); GeometryFactory factory = new GeometryFactory(new PrecisionModel(), srid); using (SqlConnection conn = new SqlConnection(connectionString)) using (SqlBulkCopy copy = new SqlBulkCopy(conn)) using (ShapefileDataReader reader = new ShapefileDataReader(shapefile, factory, transform)) { conn.Open(); string createTableSql = GenerateCreateTableQuery(reader, tableName); using (SqlCommand createTableComm = new SqlCommand(createTableSql, conn)) createTableComm.ExecuteNonQuery(); copy.SqlRowsCopied += (object sender, SqlRowsCopiedEventArgs e) => { System.Console.Clear(); System.Console.WriteLine("Copied " + e.RowsCopied); }; copy.NotifyAfter = 257; copy.DestinationTableName = tableName; copy.WriteToServer(new ShapefileBulkSqlReader(reader, srid)); } }
/// <summary> /// Renders the layer to a graphics object /// </summary> /// <param name="g">Graphics object reference</param> /// <param name="map">Map which is rendered</param> public override void OnRender(Graphics g, Map map) // TODO: remove map as parameter { if (map.Center == null) { throw (new ApplicationException("Cannot render map. View center not specified")); } if (g == null) { return; } g.SmoothingMode = SmoothingMode; //View to render IEnvelope envelope = map.Envelope; if (CoordinateTransformation != null) { envelope = GeometryTransform.TransformBox(envelope, CoordinateTransformation.MathTransform.Inverse()); } if (DataSource == null) { throw (new ApplicationException("DataSource property not set on layer '" + Name + "'")); } RenderFeatures(g, envelope, map); }
/// <summary> /// Returns the data associated with all the geometries that are intersected by 'geom' /// </summary> /// <param name="geometry">Geometry to intersect with</param> /// <param name="ds">FeatureDataSet to fill data into</param> public void ExecuteIntersectionQuery(IGeometry geometry, IFeatureCollectionSet ds) { if (CoordinateTransformation != null) { #if !DotSpatialProjections if (ReverseCoordinateTransformation != null) { geometry = GeometryTransform.TransformGeometry(geometry, ReverseCoordinateTransformation.MathTransform, GeometryServiceProvider.Instance.CreateGeometryFactory((int)ReverseCoordinateTransformation.TargetCS.AuthorityCode)); } else { CoordinateTransformation.MathTransform.Invert(); geometry = GeometryTransform.TransformGeometry(geometry, CoordinateTransformation.MathTransform, GeometryServiceProvider.Instance.CreateGeometryFactory((int)CoordinateTransformation.SourceCS.AuthorityCode)); CoordinateTransformation.MathTransform.Invert(); } #else geometry = GeometryTransform.TransformGeometry(geometry, CoordinateTransformation.Target, CoordinateTransformation.Source, CoordinateTransformation.SourceFactory); #endif } lock (_dataSource) { _dataSource.Open(); _dataSource.ExecuteIntersectionQuery(geometry, ds); _dataSource.Close(); } }
private IGeometry TransformGeo(IGeometry g) { Geometry geo = (Geometry)g; #if DDOT string wkt = "GEOGCS[\"GCS_WGS_1984\",DATUM[\"D_WGS_1984\",SPHEROID[\"WGS_1984\",6378137,298.257223563]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.017453292519943295]]"; CoordinateSystemFactory cFacWGS = new CoordinateSystemFactory(); ICoordinateSystem wgs84 = cFacWGS.CreateFromWkt(wkt); // // Acquire the state plane project from // http://spatialreference.org/ //wkt = "PROJCS[\"NAD_1983_StatePlane_Maryland_FIPS_1900_Meter\",GEOGCS[\"GCS_North_American_1983\",DATUM[\"D_North_American_1983\",SPHEROID[\"GRS_1980\",6378137,298.257222101]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.017453292519943295]],PROJECTION[\"Lambert_Conformal_Conic\"],PARAMETER[\"False_Easting\",1312333.333333333],PARAMETER[\"False_Northing\",0],PARAMETER[\"Central_Meridian\",-77],PARAMETER[\"Standard_Parallel_1\",38.3],PARAMETER[\"Standard_Parallel_2\",39.45],PARAMETER[\"Latitude_Of_Origin\",37.66666666666666],UNIT[\"Foot_US\",0.30480060960121924]]"; //wkt = "PROJCS["NAD_1983_StatePlane_Florida_West_FIPS_0902_Feet",GEOGCS["GCS_North_American_1983",DATUM["D_North_American_1983",SPHEROID["GRS_1980",6378137,298.257222101]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",656166.6666666665],PARAMETER["False_Northing",0],PARAMETER["Central_Meridian",-82],PARAMETER["Scale_Factor",0.9999411764705882],PARAMETER["Latitude_Of_Origin",24.33333333333333],UNIT["Foot_US",0.30480060960121924]]" wkt = "PROJCS[\"NAD_1983_StatePlane_Maryland_FIPS_1900_Meter\",GEOGCS[\"GCS_North_American_1983\",DATUM[\"D_North_American_1983\",SPHEROID[\"GRS_1980\",6378137,298.257222101]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.017453292519943295]],PROJECTION[\"Lambert_Conformal_Conic\"],PARAMETER[\"False_Easting\",399999.2],PARAMETER[\"False_Northing\",0],PARAMETER[\"Central_Meridian\",-77],PARAMETER[\"Standard_Parallel_1\",38.3],PARAMETER[\"Standard_Parallel_2\",39.45],PARAMETER[\"Latitude_Of_Origin\",37.66666666666666],UNIT[\"Meter\",1]]"; //wkt = "PROJCS[\"GRS_1980_Transverse_Mercator\",GEOGCS[\"GCS_GRS_1980\",DATUM[\"D_GRS_1980\",SPHEROID[\"GRS_1980\",6378137,298.257222101]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.017453292519943295]],PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"Scale_Factor\",1.00005000],PARAMETER[\"False_Easting\",164041.66666667],PARAMETER[\"False_Northing\",0],PARAMETER[\"Central_Meridian\",-96.68805556],PARAMETER[\"Latitude_Of_Origin\",40.25000000],UNIT[\"Foot_US\",0.30480060960121924]]"; CoordinateSystemFactory cFac1 = new CoordinateSystemFactory(); ICoordinateSystem nad83 = cFac1.CreateFromWkt(wkt); CoordinateTransformationFactory ctFac = new CoordinateTransformationFactory(); ICoordinateTransformation transDeg2M = ctFac.CreateFromCoordinateSystems(nad83, wgs84); //Geocentric->Geographic (WGS84) geo = GeometryTransform.TransformGeometry((Geometry)g, transDeg2M.MathTransform); #endif return(geo); }
private static IEnumerable <GeoJSON> QueryData(BoundingBox bbox, ICanQueryLayer layer) { if (layer == null) { throw new ArgumentNullException("layer"); } // Query for data FeatureDataSet ds = new FeatureDataSet(); layer.ExecuteIntersectionQuery(bbox, ds); IEnumerable <GeoJSON> data = GeoJSONHelper.GetData(ds); // Reproject geometries if needed IMathTransform transform = null; if (layer is VectorLayer) { ICoordinateTransformation transformation = (layer as VectorLayer).CoordinateTransformation; transform = transformation == null ? null : transformation.MathTransform; } if (transform != null) { GeometryFactory gf = new GeometryFactory(); data = data.Select(d => { Geometry converted = GeometryTransform.TransformGeometry(d.Geometry, transform, gf); d.SetGeometry(converted); return(d); }); } return(data); }
/// <summary> /// Returns the data associated with all the geometries that are intersected by 'geom' /// </summary> /// <param name="geometry">Geometry to intersect with</param> /// <param name="ds">FeatureDataSet to fill data into</param> public void ExecuteIntersectionQuery(Geometry geometry, FeatureDataSet ds) { if (CoordinateTransformation != null) { #if !DotSpatialProjections if (ReverseCoordinateTransformation != null) { geometry = GeometryTransform.TransformGeometry(geometry, ReverseCoordinateTransformation.MathTransform); } else { CoordinateTransformation.MathTransform.Invert(); geometry = GeometryTransform.TransformGeometry(geometry, CoordinateTransformation.MathTransform); CoordinateTransformation.MathTransform.Invert(); } #else geometry = GeometryTransform.TransformGeometry(geometry, CoordinateTransformation.Target, CoordinateTransformation.Source); #endif } lock (_dataSource) { _dataSource.Open(); _dataSource.ExecuteIntersectionQuery(geometry, ds); _dataSource.Close(); } }
public void TestConversion() { var point = GeometryFactory.Default.CreatePoint(new Coordinate(492155.73, 6303867.82)); var transform = new CoordinateTransformationFactory().CreateFromCoordinateSystems( ProjectedCoordinateSystem.WGS84_UTM(32, true), GeographicCoordinateSystem.WGS84); var transformedPoint = GeometryTransform.TransformGeometry(GeometryFactory.Default, point, transform.MathTransform); }
/// <summary> /// Utility function to transform given geometry to the source geometry /// </summary> /// <param name="geometry"></param> /// <returns></returns> protected virtual IGeometry ToSource(IGeometry geometry) { if (geometry.SRID == SRID) { return(geometry); } #if !DotSpatialProjections if (ReverseCoordinateTransformation != null) { return(GeometryTransform.TransformGeometry(geometry, ReverseCoordinateTransformation.MathTransform, SourceFactory)); } #endif if (CoordinateTransformation != null) { #if !DotSpatialProjections var mt = CoordinateTransformation.MathTransform; mt.Invert(); var res = GeometryTransform.TransformGeometry(geometry, mt, SourceFactory); mt.Invert(); return(res); #else return(GeometryTransform.TransformGeometry(geometry, CoordinateTransformation.Target, CoordinateTransformation.Source, SourceFactory)); #endif } return(geometry); }
protected Envelope ToSource(Envelope envelope) { if (ReverseCoordinateTransformation == null) { if (CoordinateTransformation == null) { return(envelope); } var mt = CoordinateTransformation.MathTransform; #if !DotSpatialProjections mt.Invert(); var res = GeometryTransform.TransformBox(envelope, mt); mt.Invert(); #else return(GeometryTransform.TransformBox(envelope, CoordinateTransformation.Target, CoordinateTransformation.Source)); #endif return(res); } #if !DotSpatialProjections return(GeometryTransform.TransformBox(envelope, ReverseCoordinateTransformation.MathTransform)); #else return(GeometryTransform.TransformBox(box, ReverseCoordinateTransformation.Source, ReverseCoordinateTransformation.Target)); #endif }
public virtual TrackerFeature GetTrackerAtCoordinate(Coordinate worldPos) { foreach (var trackerFeature in trackers) { Coordinate size; if (trackerFeature.Bitmap != null) { size = MapHelper.ImageToWorld(Layer.Map, trackerFeature.Bitmap.Width, trackerFeature.Bitmap.Height); } else { // hack for RegularGridCoverageLayer size = MapHelper.ImageToWorld(Layer.Map, 6, 6); } var boundingBox = MapHelper.GetEnvelope(worldPos, size.X, size.Y); var geom = (IPoint)trackerFeature.Geometry; if (Layer.CoordinateTransformation != null) { geom = GeometryTransform.TransformPoint(geom, Layer.CoordinateTransformation.MathTransform); } if (boundingBox.Intersects(geom.Coordinate)) { return(trackerFeature); } } return(null); }
override public FeatureList process(FeatureList input, FilterEnv env) { foreach (Feature feature in input) { CoordinateSystemFactory csf = new CoordinateSystemFactory(); ICoordinateSystem cssource = csf.CreateFromWkt(((SharpMapSpatialReference)feature.getGeometry().SpatialReference).CoordinateSystem.WKT); ICoordinateSystem cstarget; if (translateScript != null) { //Console.WriteLine(Registry.instance().GetEngine("Python").run(TranslateScript).asString()); cstarget = csf.CreateFromWkt(Registry.instance().GetEngine("Python").run(TranslateScript).asString()); } else { cstarget = csf.CreateFromWkt(env.getInputSRS().WKT); } CoordinateTransformationFactory ctf = new CoordinateTransformationFactory(); ICoordinateTransformation ct = ctf.CreateFromCoordinateSystems(cssource, cstarget); //if (feature.getGeometry().GeometryType == GeometryType2.Point) //{ // Point p = (Point)feature.getGeometry(); //GeometryTransform.TransformPoint(feature, ct.MathTransform); Geometry geom = feature.getGeometry(); Geometry geomRst = GeometryTransform.TransformGeometry(geom, ct.MathTransform); feature.setGeometry(geomRst); //} } return(input); }
private void DrawPoints(MapViewport map, IEnumerable <DataRow> features, Bitmap dot, Bitmap image) { var size = new Size(dot.Width, dot.Height); foreach (FeatureDataRow row in features) { var heatValue = HeatValueComputer(row); if (heatValue <= 0) { continue; } if (heatValue >= 1f) { heatValue = 1; } var c = row.Geometry.PointOnSurface.Coordinate; if (CoordinateTransformation != null) { c = GeometryTransform.TransformCoordinate(c, CoordinateTransformation.MathTransform); } var posF = map.WorldToImage(c); var pos = Point.Round(posF); //var pos = Point.Round(PointF.Subtract(posF, halfSize)); using (var tmpDot = ApplyHeatValueToImage(dot, heatValue)) { ImageBlender.BlendImages(image, pos.X, pos.Y, size.Width, size.Height, tmpDot, 0, 0, BlendOperation.BlendMultiply); } } }
/// <summary> /// Returns the data associated with all the geometries that are intersected by 'geom' /// </summary> /// <param name="box">Geometry to intersect with</param> /// <param name="ds">FeatureDataSet to fill data into</param> public void ExecuteIntersectionQuery(Envelope box, IFeatureCollectionSet ds) { if (CoordinateTransformation != null) { #if !DotSpatialProjections if (ReverseCoordinateTransformation != null) { box = GeometryTransform.TransformBox(box, ReverseCoordinateTransformation.MathTransform); } else { CoordinateTransformation.MathTransform.Invert(); box = GeometryTransform.TransformBox(box, CoordinateTransformation.MathTransform); CoordinateTransformation.MathTransform.Invert(); } #else box = GeometryTransform.TransformBox(box, CoordinateTransformation.Target, CoordinateTransformation.Source); #endif } lock (_dataSource) { _dataSource.Open(); _dataSource.ExecuteIntersectionQuery(box, ds); _dataSource.Close(); } }
/// <summary> /// Returns the data associated with all the geometries that are intersected by 'geom' /// </summary> /// <param name="box">Geometry to intersect with</param> /// <param name="ds">FeatureDataSet to fill data into</param> public void ExecuteIntersectionQuery(Envelope box, IFeatureCollectionSet ds) { if (CoordinateTransformation != null) { #if !DotSpatialProjections if (ReverseCoordinateTransformation != null) { box = GeometryTransform.TransformBox(box, ReverseCoordinateTransformation.MathTransform); } else { CoordinateTransformation.MathTransform.Invert(); box = GeometryTransform.TransformBox(box, CoordinateTransformation.MathTransform); CoordinateTransformation.MathTransform.Invert(); } #else box = GeometryTransform.TransformBox(box, CoordinateTransformation.Target, CoordinateTransformation.Source); #endif } lock (_dataSource) { _dataSource.Open(); int tableCount = ds.Count; _dataSource.ExecuteIntersectionQuery(box, ds); if (ds.Count > tableCount) { //We added a table, name it according to layer var table = ds[ds.Count - 1]; table.Name = LayerName; } _dataSource.Close(); } }
public static IGeometry ToSource(this Layer self, IGeometry geometry, IGeometryFactory sourceFactory) { if (geometry.SRID == sourceFactory.SRID) { return(geometry); } #if !DotSpatialProjections if (self.ReverseCoordinateTransformation != null) { return(GeometryTransform.TransformGeometry(geometry, self.ReverseCoordinateTransformation.MathTransform, sourceFactory)); } #endif if (self.CoordinateTransformation != null) { #if !DotSpatialProjections var mt = self.CoordinateTransformation.MathTransform; mt.Invert(); var res = GeometryTransform.TransformGeometry(geometry, mt, sourceFactory); mt.Invert(); return(res); #else return(GeometryTransform.TransformGeometry(geometry, self.CoordinateTransformation.Target, self.CoordinateTransformation.Source, SourceFactory)); #endif } return(geometry); }
private IGeometry TransformSingleGeometry(IGeometry g) { CoordinateTransformationFactory ctFac = new CoordinateTransformationFactory(); ICoordinateTransformation transDeg2M = ctFac.CreateFromCoordinateSystems(nad83, wgs84); //Geocentric->Geographic (WGS84) Geometry geo = GeometryTransform.TransformGeometry((Geometry)g, transDeg2M.MathTransform); return(geo); }
/// <summary> /// Utility function to transform given envelope using a specific transformation /// </summary> /// <param name="envelope">The source envelope</param> /// <param name="coordinateTransformation">The <see cref="GeoAPI.CoordinateSystems.Transformations.ICoordinateTransformation"/> to use.</param> /// <returns>The target envelope</returns> protected virtual Envelope ToTarget(Envelope envelope, ICoordinateTransformation coordinateTransformation) { if (coordinateTransformation == null) { return(envelope); } return(GeometryTransform.TransformBox(envelope, coordinateTransformation.MathTransform)); }
public void TestGeometryCollection() { const string wkt = "GEOMETRYCOLLECTION (POLYGON ((100 200, 200 200, 200 100, 100 100, 100 200)), LINESTRING (250 100, 350 200), POINT (350 150))"; var g1 = (IGeometryCollection)_reader.Read(wkt); var g2 = (IGeometryCollection)GeometryTransform.TransformGeometry(_factory, g1, _mathTransform); TestGeometry(g1, g2); }
public void TestLineString() { const string wkt = "LINESTRING(0 0, 10 10)"; var g1 = (ILineString)_reader.Read(wkt); var g2 = (ILineString)GeometryTransform.TransformGeometry(_factory, g1, _mathTransform); TestGeometry(g1, g2); }
public void TestPolygon() { const string wkt = "POLYGON ((100 200, 200 200, 200 100, 100 100, 100 200))"; var g1 = (IPolygon)_reader.Read(wkt); var g2 = (IPolygon)GeometryTransform.TransformGeometry(_factory, g1, _mathTransform); TestGeometry(g1, g2); }
public void TestPoint() { const string wkt = "POINT ( 10 20 )"; var g1 = (IPoint)_reader.Read(wkt); var g2 = (IPoint)GeometryTransform.TransformGeometry(_factory, g1, _mathTransform); TestGeometry(g1, g2); }
public void TestAlbersProjection() { var cFac = new CoordinateSystemFactory(); var ellipsoid = cFac.CreateFlattenedSphere( "Clarke 1866", 6378206.4, 294.9786982138982, LinearUnit.USSurveyFoot); var datum = cFac.CreateHorizontalDatum( "Clarke 1866", DatumType.HD_Geocentric, ellipsoid, null); var gcs = cFac.CreateGeographicCoordinateSystem( "Clarke 1866", AngularUnit.Degrees, datum, PrimeMeridian.Greenwich, new AxisInfo("Lon", AxisOrientationEnum.East), new AxisInfo("Lat", AxisOrientationEnum.North)); var 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)); var projection = cFac.CreateProjection( "Albers Conical Equal Area", "albers", parameters); var coordsys = cFac.CreateProjectedCoordinateSystem( "Albers Conical Equal Area", gcs, projection, LinearUnit.Metre, new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North)); var trans = new CoordinateTransformationFactory().CreateFromCoordinateSystems(gcs, coordsys); var f = GeometryFactory.Default; var pGeo = f.CreatePoint(new Coordinate(-75, 35)); var pUtm = GeometryTransform.TransformPoint(f, pGeo, trans.MathTransform); var pGeo2 = GeometryTransform.TransformPoint(f, pUtm, trans.MathTransform.Inverse()); var 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)); }
/// <summary> /// Check of finding a point in a given polygon /// </summary> /// <param name="connectionString">Connection string of EIDSS DB</param> /// <param name="x">Longitude of the point</param> /// <param name="y">Latitude of the point</param> /// <param name="admId">Id of country, region or rayon</param> /// <returns>True, if adm polygon contain point - x,y</returns> public static bool IsPointInside(string connectionString, double x, double y, long admId) { using (var connection = new SqlConnection(connectionString)) { connection.Open(); using (var cmd = new SqlCommand()) { //get type cmd.CommandText = string.Format("SELECT idfsGISReferenceType FROM gisBaseReference WHERE idfsGISBaseReference={0}", admId); object result = cmd.ExecuteScalar(); if (result == null || result == DBNull.Value) { return(false); } var type = (long)result; //Geoms in DB in spherical mercator. Input cooeds need to reproject! var projectedPoint = GeometryTransform.TransformPoint(new Point(x, y), CoordinateSystems.WGS84, CoordinateSystems.SphericalMercatorCS); //create query var fastQuery = String.Format(new NumberFormatInfo() { NumberDecimalSeparator = "." }, "SELECT idfsGeoObject FROM TABLE_NAME WHERE idfsGeoObject={0} AND geomShape.STContains(geometry::STGeomFromText('POINT({1} {2})', 3857))", admId, projectedPoint.X, projectedPoint.Y); switch (type) { case (long)GisDbType.RftCountry: cmd.CommandText = fastQuery.Replace("TABLE_NAME", "gisWKBCountry"); break; case (long)GisDbType.RftRegion: cmd.CommandText = fastQuery.Replace("TABLE_NAME", "gisWKBRegion"); break; case (long)GisDbType.RftRayon: cmd.CommandText = fastQuery.Replace("TABLE_NAME", "gisWKBRayon"); break; default: return(false); } result = cmd.ExecuteScalar(); return(result != null && result != DBNull.Value); } } }
protected void RenderInternal(Graphics g, Map map, BoundingBox envelope, RenderType rendertype) { if (!Style.Enabled) { return; } VectorStyle vStyle = Style.Clone(); Collection <Geometry> geoms; lock (_dataSource) { bool alreadyOpen = DataSource.IsOpen; if (!alreadyOpen) { DataSource.Open(); } geoms = DataSource.GetGeometriesInView(envelope); Console.Out.WriteLine(string.Format("Layer {0}, NumGeometries {1}", LayerName, geoms.Count)); if (!alreadyOpen) { DataSource.Close(); } } if (CoordinateTransformation != null) { for (int i = 0; i < geoms.Count; i++) #if !DotSpatialProjections { geoms[i] = GeometryTransform.TransformGeometry(geoms[i], CoordinateTransformation.MathTransform); } } #else { geoms[i] = GeometryTransform.TransformGeometry(geoms[i], CoordinateTransformation.Source, CoordinateTransformation.Target); } #endif if (vStyle.LineSymbolizer != null) { vStyle.LineSymbolizer.Begin(g, map, geoms.Count); } VectorRenderer.width = vStyle.Outline.Width; for (int i = 0; i < geoms.Count; i++) { if (geoms[i] != null) { RenderGeometry(g, map, geoms[i], vStyle, rendertype); } } if (vStyle.LineSymbolizer != null) { vStyle.LineSymbolizer.Symbolize(g, map); vStyle.LineSymbolizer.End(g, map); } }
public void TestMap2() { var m = new Map(_mapSize); m.BackgroundLayer.Add(new TileLayer(new OsmTileSource(new OsmRequest(KnownOsmTileServers.MapQuest)), "MapQuest")); var codeBase = Path.GetDirectoryName(GetType().Assembly.CodeBase); var cn = string.Format("Data Source={0};", Path.Combine(new Uri(codeBase).LocalPath, "TestData", "osm_aurich.sqlite")); var ct = Wgs84ToWebMercator; //Env[7,45731445821406 : 7,53454260528903, 53,4342695512313 : 53,478793942147] var box = new Envelope(7.45731445821406, 7.53454260528903, 53.4342695512313, 53.478793942147); var box3857 = GeometryTransform.TransformBox(box, ct.MathTransform); m.ZoomToBox(box3857); foreach (var msp in ManagedSpatiaLite.GetSpatialTables(cn)) { var l = new VectorLayer(msp.Table, msp); switch (msp.Table.Substring(0, 2).ToLower()) { case "pt": l.Style = VectorStyle.CreateRandomPuntalStyle(); break; case "ln": l.Style = VectorStyle.CreateRandomLinealStyle(); break; case "pg": l.Style = VectorStyle.CreateRandomPolygonalStyle(); break; default: l.Style = VectorStyle.CreateRandomStyle(); break; } l.CoordinateTransformation = ct; m.Layers.Add(l); } var f = GetFormatter(); BruTile.Utility.AddBruTileSurrogates(GetFormatter()); Map mD = null; Assert.DoesNotThrow(() => mD = SandD(m, f)); TestMaps("Test2", m, mD); }
/// <summary> /// Returns the data associated with all the geometries that are intersected by 'geom' /// /// Note! The table added should be named according to the LayerName! /// </summary> /// <param name="geometry">Geometry to intersect with</param> /// <param name="ds">FeatureDataSet to fill data into</param> public void ExecuteIntersectionQuery(IGeometry geometry, FeatureDataSet ds) { if (CoordinateTransformation != null) { geometry = GeometryTransform.TransformGeometry(geometry, CoordinateTransformation.MathTransform.Inverse(), geometry.Factory); } DataSource.ExecuteIntersectionQuery(geometry, ds); if (ds.Tables.Count > 0) { ds.Tables[0].TableName = LayerName; } }
/// <summary> /// Returns the data associated with all the geometries that are intersected by 'geom' /// /// Note! The table added should be named according to the LayerName! /// </summary> /// <param name="box">Bounding box to intersect with</param> /// <param name="ds">FeatureDataSet to fill data into</param> public void ExecuteIntersectionQuery(Envelope box, FeatureDataSet ds) { if (CoordinateTransformation != null) { box = GeometryTransform.TransformBox(box, CoordinateTransformation.MathTransform.Inverse()); } DataSource.ExecuteIntersectionQuery(box, ds); if (ds.Tables.Count > 0) { ds.Tables[0].TableName = LayerName; } }
/// <summary> /// Utility function to transform given envelope using a specific transformation /// </summary> /// <param name="envelope">The source envelope</param> /// <param name="coordinateTransformation">The <see cref="GeoAPI.CoordinateSystems.Transformations.ICoordinateTransformation"/> to use.</param> /// <returns>The target envelope</returns> protected virtual Envelope ToTarget(Envelope envelope, ICoordinateTransformation coordinateTransformation) { if (coordinateTransformation == null) { return(envelope); } #if !DotSpatialProjections return(GeometryTransform.TransformBox(envelope, coordinateTransformation.MathTransform)); #else return(GeometryTransform.TransformBox(envelope, coordinateTransformation.Source, coordinateTransformation.Target)); #endif }