Exemplo n.º 1
0
        protected override Feature ResizeFeatureCore(Feature sourceFeature, PointShape sourceControlPoint, PointShape targetControlPoint)
        {
            // Override the base method and modify the logic for resizing if the shape is the "custom"
            if (sourceFeature.ColumnValues.ContainsKey("Edit") && sourceFeature.ColumnValues["Edit"] == "rectangle")
            {
                PolygonShape polygonShape = sourceFeature.GetShape() as PolygonShape;

                if (polygonShape != null)
                {
                    // If the rectangle is horizontal or vertical, it will use the custom method.
                    if (string.Equals(polygonShape.GetBoundingBox().GetWellKnownText(), polygonShape.GetWellKnownText()))
                    {
                        int fixedPointIndex = GetFixedPointIndex(polygonShape, sourceControlPoint);

                        PointShape fixedPointShape = new PointShape(polygonShape.OuterRing.Vertices[fixedPointIndex]);

                        RectangleShape newRectangleShape = new LineShape(new Vertex[] { new Vertex(fixedPointShape), new Vertex(targetControlPoint) }).GetBoundingBox();

                        return(new Feature(newRectangleShape.GetWellKnownBinary(), sourceFeature.Id, sourceFeature.ColumnValues));
                    }
                }
            }

            return(base.ResizeFeatureCore(sourceFeature, sourceControlPoint, targetControlPoint));
        }
Exemplo n.º 2
0
        private LineShape getLineshape(PolygonShape polygon1, PolygonShape polygon2)
        {
            LineShape      lineToReturn        = new LineShape();
            RectangleShape polygon1BoundingBox = polygon1.GetBoundingBox();
            RectangleShape polygon2BoundingBox = polygon2.GetBoundingBox();

            Vertex vertex1 = new Vertex(polygon1BoundingBox.LowerRightPoint.X, (polygon1BoundingBox.UpperRightPoint.Y + polygon1BoundingBox.LowerRightPoint.Y) / 2);
            Vertex vertex2 = new Vertex(polygon2BoundingBox.UpperLeftPoint.X, (polygon2BoundingBox.UpperLeftPoint.Y + polygon2BoundingBox.LowerLeftPoint.Y) / 2);

            lineToReturn.Vertices.Add(vertex1);
            lineToReturn.Vertices.Add(vertex2);

            return(lineToReturn);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Set up the map with the ThinkGeo Cloud Maps overlay and a feature layer containing Frisco zoning data
        /// </summary>
        protected override void OnAppearing()
        {
            base.OnAppearing();
            // Create the background world maps using vector tiles requested from the ThinkGeo Cloud Service.
            ThinkGeoCloudVectorMapsOverlay thinkGeoCloudVectorMapsOverlay = new ThinkGeoCloudVectorMapsOverlay("9ap16imkD_V7fsvDW9I8r8ULxgAB50BX_BnafMEBcKg~", "vtVao9zAcOj00UlGcK7U-efLANfeJKzlPuDB9nw7Bp4K4UxU_PdRDg~~", ThinkGeoCloudVectorMapsMapType.Light);

            thinkGeoCloudVectorMapsOverlay.VectorTileCache = new FileVectorTileCache(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "cache"), "CloudMapsVector");

            mapView.Overlays.Add(thinkGeoCloudVectorMapsOverlay);

            // Set the Map Unit to meters (used in Spherical Mercator)
            mapView.MapUnit = GeographyUnit.Meter;


            // Create a feature layer to hold the Frisco zoning data
            ShapeFileFeatureLayer zoningLayer = new ShapeFileFeatureLayer(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Data/Shapefile/Zoning.shp"));

            // Convert the Frisco shapefile from its native projection to Spherical Mercator, to match the map
            ProjectionConverter projectionConverter = new ProjectionConverter(2276, 3857);

            zoningLayer.FeatureSource.ProjectionConverter = projectionConverter;

            // Add a style to use to draw the Frisco zoning polygons
            zoningLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
            zoningLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle    = AreaStyle.CreateSimpleAreaStyle(GeoColor.FromArgb(50, GeoColors.MediumPurple), GeoColors.MediumPurple, 2);

            // Create a layer to hold the feature we will perform the spatial query against
            InMemoryFeatureLayer queryFeatureLayer = new InMemoryFeatureLayer();

            queryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle    = AreaStyle.CreateSimpleAreaStyle(GeoColor.FromArgb(75, GeoColors.LightRed), GeoColors.LightRed);
            queryFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

            // Create a layer to hold features found by the spatial query
            InMemoryFeatureLayer highlightedFeaturesLayer = new InMemoryFeatureLayer();

            highlightedFeaturesLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle    = AreaStyle.CreateSimpleAreaStyle(GeoColor.FromArgb(90, GeoColors.MidnightBlue), GeoColors.MidnightBlue);
            highlightedFeaturesLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

            // Add each feature layer to it's own overlay
            // We do this so we can control and refresh/redraw each layer individually
            LayerOverlay layerOverlay = new LayerOverlay();

            layerOverlay.Layers.Add("Frisco Zoning", zoningLayer);
            layerOverlay.Layers.Add("Query Feature", queryFeatureLayer);
            layerOverlay.Layers.Add("Highlighted Features", highlightedFeaturesLayer);

            mapView.Overlays.Add("Layer Overlay", layerOverlay);

            // Add an event to handle new shapes that are drawn on the map
            mapView.TrackOverlay.TrackEnded += OnPolygonDrawn;

            // Add a sample shape to the map for the initial query
            PolygonShape sampleShape = new PolygonShape("POLYGON((-10779148.1848451 3916088.62700432,-10779960.3282662 3913862.39842209,-10777189.4860062 3911913.25450323,-10777179.9313777 3915754.21500743,-10779148.1848451 3916088.62700432))");

            GetFeaturesWithin(sampleShape);

            // Set the map extent to the sample shapes
            mapView.CurrentExtent = RectangleShape.ScaleUp(sampleShape.GetBoundingBox(), 20).GetBoundingBox();

            mapView.Refresh();
        }
Exemplo n.º 4
0
        /// <summary>
        /// Set up the map with the ThinkGeo Cloud Maps overlay and a feature layer containing Frisco zoning data
        /// </summary>
        protected override void OnAppearing()
        {
            base.OnAppearing();
            // Create the background world maps using vector tiles requested from the ThinkGeo Cloud Service.
            ThinkGeoCloudVectorMapsOverlay thinkGeoCloudVectorMapsOverlay = new ThinkGeoCloudVectorMapsOverlay("9ap16imkD_V7fsvDW9I8r8ULxgAB50BX_BnafMEBcKg~", "vtVao9zAcOj00UlGcK7U-efLANfeJKzlPuDB9nw7Bp4K4UxU_PdRDg~~", ThinkGeoCloudVectorMapsMapType.Light);

            thinkGeoCloudVectorMapsOverlay.VectorTileCache = new FileVectorTileCache(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "cache"), "CloudMapsVector");

            mapView.Overlays.Add(thinkGeoCloudVectorMapsOverlay);

            // Set the Map Unit to meters (used in Spherical Mercator)
            mapView.MapUnit = GeographyUnit.Meter;

            // Create a feature layer to hold the Frisco zoning data
            ShapeFileFeatureLayer zoningLayer = new ShapeFileFeatureLayer(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Data/Shapefile/Zoning.shp"));

            // Convert the Frisco shapefile from its native projection to Spherical Mercator, to match the map
            ProjectionConverter projectionConverter = new ProjectionConverter(2276, 3857);

            zoningLayer.FeatureSource.ProjectionConverter = projectionConverter;

            // Add a style to use to draw the Frisco zoning polygons
            zoningLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
            zoningLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle    = AreaStyle.CreateSimpleAreaStyle(GeoColor.FromArgb(50, GeoColors.MediumPurple), GeoColors.MediumPurple, 2);

            // Set the map extent to Frisco, TX
            // mapView.CurrentExtent = new RectangleShape(-10781137.28, 3917162.59, -10774579.34, 3911241.35);

            // Create a layer to hold the feature we will perform the spatial query against
            InMemoryFeatureLayer queryFeatureLayer = new InMemoryFeatureLayer();

            queryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle    = AreaStyle.CreateSimpleAreaStyle(GeoColor.FromArgb(75, GeoColors.LightRed), GeoColors.LightRed);
            queryFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

            // Create a layer to hold features found by the spatial query
            InMemoryFeatureLayer highlightedFeaturesLayer = new InMemoryFeatureLayer();

            highlightedFeaturesLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle    = AreaStyle.CreateSimpleAreaStyle(GeoColor.FromArgb(90, GeoColors.MidnightBlue), GeoColors.MidnightBlue);
            highlightedFeaturesLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

            // Add each feature layer to it's own overlay
            // We do this so we can control and refresh/redraw each layer individually
            LayerOverlay layerOverlay = new LayerOverlay();

            layerOverlay.Layers.Add("Frisco Zoning", zoningLayer);
            layerOverlay.Layers.Add("Query Feature", queryFeatureLayer);
            layerOverlay.Layers.Add("Highlighted Features", highlightedFeaturesLayer);

            mapView.Overlays.Add("Layer Overlay", layerOverlay);

            // Add an event to handle new shapes that are drawn on the map
            mapView.TrackOverlay.TrackEnded += OnPolygonDrawn;

            // Add a sample shape to the map for the initial query
            PolygonShape sampleShape = new PolygonShape("POLYGON((-10779549.4792414 3915352.92061116,-10777495.2341177 3915859.31592073,-10776214.913901 3914827.41589883,-10776081.1491022 3913384.66699796,-10777906.0831424 3912553.41431997,-10779702.3532971 3914110.81876263,-10779549.4792414 3915352.92061116))");

            GetFeaturesOverlaps(sampleShape);

            // Set the map extent to the sample shapes
            mapView.CurrentExtent = RectangleShape.ScaleUp(sampleShape.GetBoundingBox(), 20).GetBoundingBox();

            mapView.Refresh();
        }
Exemplo n.º 5
0
        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;
                }
            }
        }
Exemplo n.º 6
0
        public void Load(GeocodeMatch match)
        {
            centroidPoint = null;
            boundingBox   = null;

            if (match.MatchResults.Count > 0 &&
                (match.MatchResults.ContainsKey("City") ||
                 match.MatchResults.ContainsKey("State") ||
                 match.MatchResults.ContainsKey("County") ||
                 match.MatchResults.ContainsKey("Zip") ||
                 match.MatchResults.ContainsKey("Street") ||
                 match.MatchResults.ContainsKey("CentroidPoint") ||
                 match.MatchResults.ContainsKey("BoundingBox")))
            {
                if (match.MatchResults.ContainsKey("City"))
                {
                    City = match.MatchResults["City"];
                }
                if (match.MatchResults.ContainsKey("State"))
                {
                    State = match.MatchResults["State"];
                }
                if (match.MatchResults.ContainsKey("County"))
                {
                    County = match.MatchResults["County"];
                }
                if (match.MatchResults.ContainsKey("Zip"))
                {
                    Zipcode = match.MatchResults["Zip"];
                }
                if (match.MatchResults.ContainsKey("CentroidPoint"))
                {
                    centroidPoint = new PointShape(match.MatchResults["CentroidPoint"]);
                }
                if (match.MatchResults.ContainsKey("BoundingBox"))
                {
                    boundingBox = new RectangleShape(match.MatchResults["BoundingBox"]);
                }
                if (match.MatchResults.ContainsKey("Street"))
                {
                    if (match.MatchResults.ContainsKey("HouseNumber"))
                    {
                        Address = match.MatchResults["HouseNumber"] + " " + match.MatchResults["Street"];
                    }
                    else
                    {
                        Address = match.MatchResults["Street"];
                    }
                }

                if (match.MatchResults.ContainsKey(SearchPlaceViewModel.InternalProjectionKey))
                {
                    internalProjection = match.MatchResults[SearchPlaceViewModel.InternalProjectionKey];
                }
                if (match.MatchResults.ContainsKey("SearchSegment"))
                {
                    searchSegment = match.MatchResults["SearchSegment"];
                }
            }
            else if (match.MatchResults.ContainsKey("mtrs") ||
                     match.MatchResults.ContainsKey("COUNTYNA") ||
                     match.MatchResults.ContainsKey("ABSTRACT"))
            {
                if (match.MatchResults.ContainsKey("CenterWkt"))
                {
                    centroidPoint = new PointShape(match.MatchResults["CenterWkt"]);
                }
                if (match.MatchResults.ContainsKey("BoundingBoxWkt"))
                {
                    PolygonShape polygon = new PolygonShape(match.MatchResults["BoundingBoxWkt"]);
                    boundingBox = polygon.GetBoundingBox();
                }

                string addressText = string.Empty;
                if (match.MatchResults.ContainsKey("mtrs"))
                {
                    addressText = match.MatchResults["mtrs"];
                }
                else
                {
                    if (match.MatchResults.ContainsKey("COUNTYNAME"))
                    {
                        addressText = match.MatchResults["COUNTYNAME"];
                    }
                    if (match.MatchResults.ContainsKey("ABSTRACT"))
                    {
                        addressText += "," + match.MatchResults["ABSTRACT"];
                    }
                    if (match.MatchResults.ContainsKey("SECTION"))
                    {
                        addressText += "," + match.MatchResults["SECTION"];
                    }
                    if (match.MatchResults.ContainsKey("FID"))
                    {
                        addressText += "," + match.MatchResults["FID"];
                    }
                    if (match.MatchResults.ContainsKey("SURVEY"))
                    {
                        addressText += "," + match.MatchResults["SURVEY"];
                    }
                    if (match.MatchResults.ContainsKey("BLOCK"))
                    {
                        addressText += "," + match.MatchResults["BLOCK"];
                    }
                    if (match.MatchResults.ContainsKey("SUBSURVEY"))
                    {
                        addressText += "," + match.MatchResults["SUBSURVEY"];
                    }
                    if (match.MatchResults.ContainsKey("COUNTYID"))
                    {
                        addressText += "," + match.MatchResults["COUNTYID"];
                    }
                }
                Address = addressText;
            }
            RaisePropertyChanged(() => IsEmpty);
        }