private void mapView_Loaded(object sender, RoutedEventArgs e) { mapView.MapUnit = GeographyUnit.Meter; mapView.ZoomLevelSet = new ThinkGeoCloudMapsZoomLevelSet(); mapView.CurrentExtent = new RectangleShape(-15495673, 20037508, 13458526, -20037508); // Create background world map with vector tile requested from ThinkGeo Cloud Service. ThinkGeoCloudVectorMapsOverlay thinkGeoCloudVectorMapsOverlay = new ThinkGeoCloudVectorMapsOverlay(SampleHelper.ThinkGeoCloudId, SampleHelper.ThinkGeoCloudSecret, ThinkGeoCloudVectorMapsMapType.Light); mapView.Overlays.Add(thinkGeoCloudVectorMapsOverlay); // Setup the shapefile layer. ShapeFileFeatureLayer worldLayer = new ShapeFileFeatureLayer(SampleHelper.Get("Countries02_3857.shp")); worldLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyle.CreateSimpleAreaStyle(GeoColors.Transparent, GeoColor.FromArgb(100, GeoColors.Green)); worldLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; // Setup the mapshape layer. InMemoryFeatureLayer bitmapLayer = new InMemoryFeatureLayer(); bitmapLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle.PointType = PointType.Image; bitmapLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle.Image = new GeoImage(SampleHelper.Get("Prop Plane.png")); bitmapLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyle.CreateSimpleLineStyle(GeoColors.Red, 1F, LineDashStyle.Dash, false); bitmapLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; ProjectionConverter project = new ProjectionConverter(4326, 3857); project.Open(); PointShape planeShape = new PointShape(-95.2806, 38.9554); PointShape destinationPoint = new PointShape(36.04, 48.49); MultilineShape airLineShape = (MultilineShape)project.ConvertToExternalProjection(planeShape.GreatCircle(destinationPoint)); airLineShape.Id = "AirLine"; bitmapLayer.Open(); bitmapLayer.EditTools.BeginTransaction(); bitmapLayer.EditTools.Add(new Feature(project.ConvertToExternalProjection(planeShape).GetWellKnownBinary(), "Plane")); bitmapLayer.EditTools.Add(new Feature(airLineShape.GetWellKnownBinary(), "AirLine")); bitmapLayer.EditTools.CommitTransaction(); bitmapLayer.Close(); project.Close(); LayerOverlay worldOverlay = new LayerOverlay(); worldOverlay.Layers.Add("WorldLayer", worldLayer); mapView.Overlays.Add("WorldOverlay", worldOverlay); LayerOverlay planeOverlay = new LayerOverlay(); planeOverlay.TileType = TileType.SingleTile; planeOverlay.Layers.Add("BitmapLayer", bitmapLayer); mapView.Overlays.Add("PlaneOverlay", planeOverlay); mapView.Refresh(); timer.Start(); }
private void MapView_Loaded(object sender, RoutedEventArgs e) { mapView.MapUnit = GeographyUnit.DecimalDegree; mapView.CurrentExtent = new RectangleShape(-177.39584350585937, 83.113876342773437, -52.617362976074219, 14.550546646118164); ShapeFileFeatureLayer worldLayer = new ShapeFileFeatureLayer(SampleHelper.Get("Countries02_3857.shp")); worldLayer.Open(); ProjectionConverter project = new ProjectionConverter(3857, 4326); project.Open(); Feature feature = project.ConvertToExternalProjection(worldLayer.QueryTools.GetFeatureById("135", new string[0])); project.Close(); areaBaseShape = (AreaBaseShape)feature.GetShape(); worldLayer.Close(); InMemoryFeatureLayer simplificationLayer = new InMemoryFeatureLayer(); simplificationLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; simplificationLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyle.CreateSimpleAreaStyle(GeoColor.FromArgb(255, 233, 232, 214), GeoColor.FromArgb(255, 118, 138, 69)); simplificationLayer.InternalFeatures.Add(feature); LayerOverlay simplificationOverlay = new LayerOverlay(); simplificationOverlay.TileType = TileType.SingleTile; simplificationOverlay.Layers.Add(new BackgroundLayer(new GeoSolidBrush(GeoColors.DeepOcean))); simplificationOverlay.Layers.Add("SimplificationLayer", simplificationLayer); mapView.Overlays.Add("SimplificationOverlay", simplificationOverlay); cmbSimplificationType.SelectedIndex = 0; cmbTolerance.SelectedIndex = 0; mapView.Refresh(); }
private void mapView_MapClick(object sender, MapClickMapViewEventArgs e) { FeatureLayer worldLayer = mapView.FindFeatureLayer("WorldLayer"); // Find the country the user clicked on. worldLayer.Open(); Collection <Feature> selectedFeatures = worldLayer.QueryTools.GetFeaturesContaining(e.WorldLocation, new string[1] { "CNTRY_NAME" }); worldLayer.Close(); // Determine the area of the country. if (selectedFeatures.Count > 0) { ProjectionConverter project = new ProjectionConverter(3857, 4326); project.Open(); AreaBaseShape areaShape = (AreaBaseShape)project.ConvertToExternalProjection(selectedFeatures[0].GetShape()); project.Close(); double area = areaShape.GetArea(GeographyUnit.DecimalDegree, AreaUnit.SquareKilometers); string areaMessage = string.Format(CultureInfo.InvariantCulture, "{0} has an area of \r{1:N0} square kilometers.", selectedFeatures[0].ColumnValues["CNTRY_NAME"].Trim(), area); Popup popup = new Popup(e.WorldLocation); popup.Content = areaMessage; PopupOverlay popupOverlay = (PopupOverlay)mapView.Overlays["PopupOverlay"]; popupOverlay.Popups.Clear(); popupOverlay.Popups.Add(popup); popupOverlay.Refresh(); } }
private void btnGetDistance_Click(object sender, RoutedEventArgs e) { InMemoryFeatureLayer usInMemoryLayer = (InMemoryFeatureLayer)mapView.FindFeatureLayer("USInMemoryFeatureLayer"); InMemoryFeatureLayer chinaInMemoryLayer = (InMemoryFeatureLayer)mapView.FindFeatureLayer("ChinaInMemoryFeatureLayer"); ProjectionConverter project = new ProjectionConverter(3857, 4326); project.Open(); BaseShape usShape = project.ConvertToExternalProjection(usInMemoryLayer.InternalFeatures["US"].GetShape()); BaseShape chinaShape = project.ConvertToExternalProjection(chinaInMemoryLayer.InternalFeatures["CHINA"].GetShape()); project.Close(); double distance = usShape.GetDistanceTo(chinaShape, GeographyUnit.DecimalDegree, DistanceUnit.Kilometer); txtDistance.Text = string.Format(CultureInfo.InvariantCulture, "{0 :N4} Km", distance); }
private void mapView_MapClick(object sender, MapClickMapViewEventArgs e) { ProjectionConverter project = new ProjectionConverter(3857, 4326); project.Open(); var worldPointInDecimalDegree = project.ConvertToExternalProjection(e.WorldX, e.WorldY); TBLonLat.Text = string.Format(CultureInfo.InvariantCulture, "X={0}, Y={1}", worldPointInDecimalDegree.X.ToString("N4", CultureInfo.InvariantCulture), worldPointInDecimalDegree.Y.ToString("N4", CultureInfo.InvariantCulture)); project.Close(); }
private void mapView_MapClick(object sender, MapClickMapViewEventArgs e) { screenPosition.Text = "(" + e.ScreenX + ", " + e.ScreenY + ")"; ProjectionConverter project = new ProjectionConverter(3857, 4326); project.Open(); var worldPointInDecimalDegree = project.ConvertToExternalProjection(e.WorldX, e.WorldY); worldPosition.Text = string.Format(CultureInfo.InvariantCulture, "({0}, {1})", worldPointInDecimalDegree.X.ToString("N4", CultureInfo.InvariantCulture), worldPointInDecimalDegree.Y.ToString("N4", CultureInfo.InvariantCulture)); project.Close(); }
/// <summary> /// Use the ProjectionConverter to reproject multiple features /// </summary> private Collection <Feature> ReprojectMultipleFeatures(Collection <Feature> decimalDegreeFeatures) { //Create a new ProjectionConverter to convert between Decimal Degrees(4326) and Spherical Mercator(3857) ProjectionConverter projectionConverter = new ProjectionConverter(4326, 3857); //Convert the feature to Spherical Mercator projectionConverter.Open(); Collection <Feature> sphericalMercatorFeatures = projectionConverter.ConvertToExternalProjection(decimalDegreeFeatures); projectionConverter.Close(); //Return the reprojected features return(sphericalMercatorFeatures); }
/// <summary> /// Use the ProjectionConverter to reproject a single feature /// </summary> private Feature ReprojectFeature(Feature decimalDegreeFeature) { //Create a new ProjectionConverter to convert between Decimal Degrees(4326) and Spherical Mercator(3857) ProjectionConverter projectionConverter = new ProjectionConverter(4326, 3857); //Convert the feature to Spherical Mercator projectionConverter.Open(); Feature sphericalMercatorFeature = projectionConverter.ConvertToExternalProjection(decimalDegreeFeature); projectionConverter.Close(); //Return the reprojected feature return(sphericalMercatorFeature); }
/// <summary> /// Zoom to a lat/lon at a desired scale by converting the lat/lon to match the map's projection /// </summary> private async void ZoomToLatLon_Click(object sender, EventArgs e) { await CollapseExpander(); // Create a PointShape from the lat-lon var latlonPoint = new PointShape(Convert.ToDouble(latitude.Text), Convert.ToDouble(longitude.Text)); // Convert the lat-lon projection to match the map var projectionConverter = new ProjectionConverter(4326, 3857); projectionConverter.Open(); var convertedPoint = (PointShape)projectionConverter.ConvertToExternalProjection(latlonPoint); projectionConverter.Close(); // Zoom to the converted lat-lon at the desired scale mapView.ZoomTo(convertedPoint, Convert.ToDouble(latlonScale.Text)); }
private void mapView_MapClick(object sender, MapClickMapViewEventArgs e) { FeatureLayer worldLayer = mapView.FindFeatureLayer("RoadLayer"); InMemoryFeatureLayer highlightLayer = (InMemoryFeatureLayer)mapView.FindFeatureLayer("HighlightLayer"); Overlay highlightOverlay = mapView.Overlays["HighlightOverlay"]; // Find the road the user clicked on. worldLayer.Open(); Collection <Feature> selectedFeatures = worldLayer.QueryTools.GetFeaturesNearestTo(e.WorldLocation, GeographyUnit.Meter, 1, new string[1] { "FENAME" }); worldLayer.Close(); //Determine the length of the road. if (selectedFeatures.Count > 0) { LineBaseShape lineShape = (LineBaseShape)selectedFeatures[0].GetShape(); highlightLayer.Open(); highlightLayer.InternalFeatures.Clear(); highlightLayer.InternalFeatures.Add(new Feature(lineShape)); highlightLayer.Close(); ProjectionConverter project = new ProjectionConverter(3857, 4326); project.Open(); double length = ((LineBaseShape)project.ConvertToExternalProjection(lineShape)).GetLength(GeographyUnit.DecimalDegree, DistanceUnit.Meter); project.Close(); string lengthMessage = string.Format(CultureInfo.InvariantCulture, "{0} has a length of {1:F2} meters.", selectedFeatures[0].ColumnValues["FENAME"].Trim(), length); Popup popup = new Popup(e.WorldLocation); popup.Content = lengthMessage; PopupOverlay popupOverlay = (PopupOverlay)mapView.Overlays["PopupOverlay"]; popupOverlay.Popups.Clear(); popupOverlay.Popups.Add(popup); highlightOverlay.Refresh(); popupOverlay.Refresh(); } }
private void FindWithinDistanceFeatures() { if (mapView.Overlays.Count > 0) { FeatureLayer worldLayer = mapView.FindFeatureLayer("WorldLayer"); InMemoryFeatureLayer highlightLayer = (InMemoryFeatureLayer)mapView.FindFeatureLayer("HighlightLayer"); // Find the countries within special distance. double distance = Convert.ToDouble(cmbDistance.SelectedItem.ToString().Split(':')[1], CultureInfo.InvariantCulture); worldLayer.Open(); worldLayer.FeatureSource.ProjectionConverter = project; Collection <Feature> selectedFeatures = worldLayer.QueryTools.GetFeaturesWithinDistanceOf((PointShape)project.ConvertToExternalProjection(pointShape), GeographyUnit.DecimalDegree, DistanceUnit.Kilometer, distance, new string[0]); worldLayer.FeatureSource.ProjectionConverter = null; worldLayer.Close(); if (highlightLayer.InternalFeatures.Count > 0) { highlightLayer.InternalFeatures.Clear(); } highlightLayer.InternalFeatures.Add("Point", new Feature(pointShape)); foreach (Feature feature in selectedFeatures) { highlightLayer.InternalFeatures.Add(feature.Id, project.ConvertToInternalProjection(feature)); } mapView.Overlays["HighlightOverlay"].Refresh(); } }
private void ExtractTiles(PolygonShape polygonShape, string targetFilePath) { RectangleShape bbox = polygonShape.GetBoundingBox(); List <VectorTileRange> tileRanges = new List <VectorTileRange>(); for (int zoomLevel = 0; zoomLevel <= maxZoom; zoomLevel++) { VectorTileRange tileRange = GetTileRange(zoomLevel, bbox); tileRanges.Add(tileRange); } ThinkGeoMBTilesLayer.CreateDatabase(targetFilePath); var targetDBConnection = new SqliteConnection($"Data Source={targetFilePath}"); targetDBConnection.Open(); var targetMap = new TilesTable(targetDBConnection); var targetMetadata = new MetadataTable(targetDBConnection); var sourceDBConnection = new SqliteConnection($"Data Source={mbtilesPathFilename}"); sourceDBConnection.Open(); var sourceMap = new TilesTable(sourceDBConnection); var sourceMetadata = new MetadataTable(sourceDBConnection); sourceMetadata.ReadAllEntries(); ProjectionConverter projection = new ProjectionConverter(3857, 4326); projection.Open(); var wgs84BBox = projection.ConvertToExternalProjection(bbox); foreach (MetadataEntry entry in sourceMetadata.Entries) { if (entry.Name.Equals("center")) { PointShape centerPoint = wgs84BBox.GetCenterPoint(); entry.Value = $"{centerPoint.X},{centerPoint.Y},{maxZoom}"; } else if (entry.Name.Equals("bounds")) { entry.Value = $"{wgs84BBox.UpperLeftPoint.X},{wgs84BBox.UpperLeftPoint.Y},{wgs84BBox.LowerRightPoint.X},{wgs84BBox.LowerRightPoint.Y}"; } } targetMetadata.Insert(sourceMetadata.Entries); int recordLimit = 1000; foreach (var tileRange in tileRanges) { long offset = 0; bool isEnd = false; while (!isEnd) { string querySql = $"SELECT * FROM {sourceMap.TableName} WHERE " + ConvetToSqlString(tileRange) + $" LIMIT {offset},{recordLimit}"; var entries = sourceMap.Query(querySql); for (int i = entries.Count - 1; i >= 0; i--) { RectangleShape pbfExtent = GetPbfTileExent((int)entries[i].ZoomLevel, entries[i].TileColumn, entries[i].TileRow); if (polygonShape.IsDisjointed(pbfExtent)) { entries.RemoveAt(i); } } targetMap.Insert(entries); if (entries.Count < recordLimit) { isEnd = true; } offset = offset + recordLimit; } } }