Example #1
0
        private void btnRaiseEvent_Click(object sender, EventArgs e)
        {
            cancel                 = false;
            gbProgress.Visible     = true;
            processedCount         = 0;
            pgBuildingData.Minimum = 0;
            pgBuildingData.Value   = 0;

            ShapeFileFeatureSource featureSource = new ShapeFileFeatureSource(Path.Combine(rootPath, "DallasCounty-4326.shp"));

            featureSource.Open();
            pgBuildingData.Maximum = featureSource.GetCount();
            lbTotalCount.Text      = pgBuildingData.Maximum.ToString(CultureInfo.InvariantCulture);
            featureSource.Close();

            RtgRoutingSource.GenerateRoutingData(Path.Combine(rootPath, "BuildingRoutingDataEvent.rtg"), featureSource, BuildRoutingDataMode.Rebuild, "DallasCounty-4326.shp");
            if (cancel)
            {
                MessageBox.Show("Building routing data has been cancelled!");
            }
            else
            {
                MessageBox.Show("Finish building routing data!");
            }
            gbProgress.Visible = false;
        }
Example #2
0
        //
        // GET: /ExecuteSqlQuery/

        public ActionResult ExecuteSqlQuery()
        {
            Collection <Country> countries = new Collection <Country>();

            if (HttpContext.Request.QueryString.Count > 0)
            {
                string sql = ControllerContext.HttpContext.Request.Form["SQLTextBox"].ToString().ToLowerInvariant();

                ShapeFileFeatureSource featureSource = new ShapeFileFeatureSource(Server.MapPath("~/App_Data/cntry02.shp"));
                featureSource.Open();
                DataTable dataTable = featureSource.ExecuteQuery(sql);
                featureSource.Close();

                foreach (DataRow row in dataTable.Rows)
                {
                    Country country = new Country();
                    country.CountryName = row["cntry_name"].ToString();
                    country.Population  = row["pop_cntry"].ToString();

                    countries.Add(country);
                }
            }

            return(View(countries));
        }
Example #3
0
        private void btnGenerateRoadData_Click(object sender, EventArgs e)
        {
            // Please uncomment the code below to disassemble the shapefile
            // RoutingHelper.GenerateRoutableShapeFile(@"..\..\SampleData\Edmonton.shp", @"..\..\SampleData\RoutableEdmonton.shp");

            ShapeFileFeatureSource disassembledFeatureSource = new ShapeFileFeatureSource(@"..\..\SampleData\RoutableEdmonton.shp");

            disassembledFeatureSource.Open();
            lbDisassebledCount.Text = disassembledFeatureSource.GetCount().ToString(CultureInfo.InvariantCulture);
            disassembledFeatureSource.Close();

            MessageBox.Show("Finish building routing data!");
        }
Example #4
0
        /// <summary>
        /// Setup the map with the ThinkGeo Cloud Maps overlay. Also, add the ISOLine layer to the map
        /// </summary>
        protected override void OnAppearing()
        {
            base.OnAppearing();
            // It is important to set the map unit first to either feet, meters or decimal degrees.
            mapView.MapUnit = GeographyUnit.Meter;

            // Create background world map with vector tile requested from ThinkGeo Cloud Service.
            var 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);

            // Create a new overlay that will hold our new layer and add it to the map.
            LayerOverlay isoLineOverlay = new LayerOverlay();

            mapView.Overlays.Add("isoLineOverlay", isoLineOverlay);

            // Load a csv file with the mosquito data that we will use for the iso line.
            Dictionary <PointShape, double> csvPointData = GetDataFromCSV(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Data/Csv/Frisco_Mosquitos.csv"));

            // Create the layer based on the method GetDynamicIsoLineLayer and pass in the points we loaded above and add it to the map.
            //  We then set the drawing quality high so we get a crisp rendering.
            var isoLineLayer = GetDynamicIsoLineLayer(csvPointData);

            isoLineOverlay.Layers.Add("IsoLineLayer", isoLineLayer);
            isoLineOverlay.DrawingQuality = DrawingQuality.HighQuality;

            // Create a layer that so we can get the current extent below to set the maps extend
            // We wont use it after so later in the code we will just close it.
            var mosquitosLayer = new ShapeFileFeatureSource(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Data/Shapefile/Frisco_Mosquitos.shp"));

            mosquitosLayer.ProjectionConverter = new ProjectionConverter(2276, 3857);

            // Open the layer and set the map view current extent to the bounding box of the layer scaled up just a bit then close the layer
            mosquitosLayer.Open();
            mapView.CurrentExtent = mosquitosLayer.GetBoundingBox();
            mosquitosLayer.Close();

            // Refresh the map.
            mapView.Refresh();
        }
Example #5
0
        private void Form_Load(object sender, EventArgs e)
        {
            // It is important to set the map unit first to either feet, meters or decimal degrees.
            mapView.MapUnit = GeographyUnit.Meter;

            // Create background world map with vector tile requested from ThinkGeo Cloud Service.
            ThinkGeoCloudVectorMapsOverlay thinkGeoCloudVectorMapsOverlay = new ThinkGeoCloudVectorMapsOverlay("itZGOI8oafZwmtxP-XGiMvfWJPPc-dX35DmESmLlQIU~", "bcaCzPpmOG6le2pUz5EAaEKYI-KSMny_WxEAe7gMNQgGeN9sqL12OA~~", ThinkGeoCloudVectorMapsMapType.Light);

            mapView.Overlays.Add(thinkGeoCloudVectorMapsOverlay);

            // Create a new overlay that will hold our new layer and add it to the map.
            LayerOverlay isoLineOverlay = new LayerOverlay();

            mapView.Overlays.Add("isoLineOverlay", isoLineOverlay);

            // Load a csv file with the mosquito data that we will use for the iso line.
            Dictionary <PointShape, double> csvPointData = GetDataFromCSV(@"../../../data/Csv/Frisco_Mosquitos.csv");

            // Create the layer based on the method GetDynamicIsoLineLayer and pass in the points we loaded above and add it to the map.
            //  We then set the drawing quality high so we get a crisp rendering.
            var isoLineLayer = GetDynamicIsoLineLayer(csvPointData);

            isoLineOverlay.Layers.Add("IsoLineLayer", isoLineLayer);
            isoLineOverlay.DrawingQuality = DrawingQuality.HighQuality;

            // Create a layer that so we can get the current extent below to set the maps extend
            // We wont use it after so later in the code we will just close it.
            var mosquitosLayer = new ShapeFileFeatureSource(@"../../../data/Shapefile/Frisco_Mosquitos.shp");

            mosquitosLayer.ProjectionConverter = new ProjectionConverter(2276, 3857);

            // Open the layer and set the map view current extent to the bounding box of the layer scaled up just a bit then close the layer
            mosquitosLayer.Open();
            mapView.CurrentExtent = mosquitosLayer.GetBoundingBox();
            mosquitosLayer.Close();

            // Refresh the map.
            mapView.Refresh();
        }
Example #6
0
        void routingEngine_GeneratingServiceArea(object sender, GeneratingServiceAreaRoutingEngineEventArgs e)
        {
            Collection <string> featureIds = GetFeatureIds(e.AccessibleFeatureIds);

            RectangleShape         rectangleShape = GetBoundingBoxByIds(featureIds);
            ShapeFileFeatureSource source         = new ShapeFileFeatureSource(@"..\..\SampleData\ghospitl.shp");

            source.Open();
            Collection <Feature> features = source.GetFeaturesInsideBoundingBox(rectangleShape, new string[] { "NAME" });

            source.Close();
            if (features.Count >= facilityCount)
            {
                InMemoryFeatureLayer facilityLayer = (InMemoryFeatureLayer)((LayerOverlay)winformsMap1.Overlays["RoutingOverlay"]).Layers["FacilityLayer"];
                foreach (Feature item in features)
                {
                    facilityLayer.InternalFeatures.Add(item);
                }

                e.IsTermination = true;
            }
        }
        private void wpfMap1_MapClick(object sender, MapClickWpfMapEventArgs e)
        {
            try
            {
                //Uses the WrapDatelineProjection to create the target pointshape for GetFeatureNearestTo spatial query function.
                WrapDatelineProjection wrapDatelineProjection = new WrapDatelineProjection();
                //Sets the HalfExtentWidth of the wrapdateline overlay we want to apply the projection on.
                //Here it is 180 because, the full extent width is 360.
                wrapDatelineProjection.HalfExtentWidth = wpfMap1.Overlays["WMK"].GetBoundingBox().Width / 2;//180;

                //Gets the valid world coordinate regardless to where the user click on the map
                wrapDatelineProjection.Open();
                Vertex projVertex = wrapDatelineProjection.ConvertToExternalProjection(e.WorldX, e.WorldY);
                wrapDatelineProjection.Close();

                //Here we just use the feature source of the shapefile because we don't display it, we just use it for doing the spatial query.
                ShapeFileFeatureSource shapeFileFeatureSource = new ShapeFileFeatureSource(@"../../data/countries02.shp");
                shapeFileFeatureSource.Open();
                //Uses the projected X and Y values for the Spatial Query.
                Collection <Feature> features = shapeFileFeatureSource.GetFeaturesNearestTo(new PointShape(projVertex), wpfMap1.MapUnit, 1, ReturningColumnsType.NoColumns);
                shapeFileFeatureSource.Close();

                LayerOverlay         dynamicOverlay       = (LayerOverlay)wpfMap1.Overlays["DynamicOverlay"];
                InMemoryFeatureLayer inMemoryFeatureLayer = (InMemoryFeatureLayer)dynamicOverlay.Layers["SelectLayer"];

                //Clears the InMemoryFeatureLayer and add the feature as the result of the spatial query.
                inMemoryFeatureLayer.Open();
                inMemoryFeatureLayer.InternalFeatures.Clear();
                inMemoryFeatureLayer.InternalFeatures.Add(features[0]);
                inMemoryFeatureLayer.Close();

                //Refreshes only the overlay with the updated InMemoryFeatureLayer.
                wpfMap1.Refresh(dynamicOverlay);
            }
            catch { }
        }
Example #8
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 and display the zoning data
            InMemoryFeatureLayer zoningLayer = new InMemoryFeatureLayer();

            // 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);

            // Import the features from the Frisco zoning data shapefile
            ShapeFileFeatureSource zoningDataFeatureSource = new ShapeFileFeatureSource(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Data/Shapefile/Zoning.shp"));

            // Create a ProjectionConverter to convert the shapefile data from North Central Texas (2276) to Spherical Mercator (3857)
            ProjectionConverter projectionConverter = new ProjectionConverter(3857, 2276);

            // For this sample, we have to reproject the features before adding them to the feature layer
            // This is because the topological equality query often does not work when used on a feature layer with a ProjectionConverter, due to rounding issues between projections
            zoningDataFeatureSource.Open();
            projectionConverter.Open();
            foreach (Feature zoningFeature in zoningDataFeatureSource.GetAllFeatures(ReturningColumnsType.AllColumns))
            {
                Feature reprojectedFeature = projectionConverter.ConvertToInternalProjection(zoningFeature);
                zoningLayer.InternalFeatures.Add(reprojectedFeature);
            }
            zoningDataFeatureSource.Close();
            projectionConverter.Close();

            // 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);

            // Create a sample shape using vertices from an existing feature, to ensure that it is touching other features
            zoningLayer.Open();
            MultipolygonShape firstFeatureShape = (MultipolygonShape)zoningLayer.FeatureSource.GetAllFeatures(ReturningColumnsType.NoColumns).First().GetShape();

            // Get vertices from an existing feature
            var vertices = firstFeatureShape.Polygons.First().OuterRing.Vertices;

            // Create a new feature using a subset of those vertices
            MultipolygonShape sampleShape = new MultipolygonShape(new Collection <PolygonShape> {
                new PolygonShape(new RingShape(new Collection <Vertex> {
                    vertices[0], vertices[1], vertices[2]
                }))
            });

            queryFeatureLayer.InternalFeatures.Add(new Feature(sampleShape));
            zoningLayer.Close();
            GetFeaturesTouching(sampleShape);

            // Set the map extent to the sample shape
            mapView.CurrentExtent = new RectangleShape(-10778499.3056056, 3920951.91647677, -10774534.1347853, 3917536.13679426);

            mapView.Refresh();
        }