Beispiel #1
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 the background world maps using vector tiles requested from the ThinkGeo Cloud Service and add it to the map.
            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 fileGeoDatabaseOverlay = new LayerOverlay();

            mapView.Overlays.Add(fileGeoDatabaseOverlay);

            // Create the new layer and set the projection as the data is in srid 2276 and our background is srid 3857 (spherical mercator).
            FileGeoDatabaseFeatureLayer fileGeoDatabaseFeatureLayer = new FileGeoDatabaseFeatureLayer(@"../../../Data/FileGeoDatabase/zoning.gdb");

            fileGeoDatabaseFeatureLayer.FeatureSource.ProjectionConverter = new ProjectionConverter(2276, 3857);
            fileGeoDatabaseFeatureLayer.ActiveLayer = "zoning";

            // Add the layer to the overlay we created earlier.
            fileGeoDatabaseOverlay.Layers.Add("Zoning", fileGeoDatabaseFeatureLayer);

            // Create an Area style on zoom level 1 and then apply it to all zoom levels up to 20.
            fileGeoDatabaseFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle    = new AreaStyle(GeoPens.Black, new GeoSolidBrush(new GeoColor(50, GeoColors.Blue)));
            fileGeoDatabaseFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

            // Open the layer and set the map view current extent to the bounding box of the layer.
            fileGeoDatabaseFeatureLayer.Open();
            mapView.CurrentExtent = fileGeoDatabaseFeatureLayer.GetBoundingBox();

            //Refresh the map.
            mapView.Refresh();
        }
Beispiel #2
0
        protected override FeatureLayer CreateFeatureLayerCore(ConfigureFeatureLayerParameters featureLayerStructureParameters)
        {
            string layerPath = LayerPluginHelper.GetLayerUriToSave(featureLayerStructureParameters.LayerUri, ExtensionFilter);
            string fileName  = Path.GetFileNameWithoutExtension(layerPath);

            if (string.IsNullOrEmpty(layerPath))
            {
                return(null);
            }
            if (fileName.FirstOrDefault() != null && Char.IsNumber(fileName.FirstOrDefault()))
            {
                MessageBox.Show("Table name can not start with number.");
                return(null);
            }
            featureLayerStructureParameters.LayerUri = new Uri(layerPath);

            Collection <FeatureSourceColumn> columns = new Collection <FeatureSourceColumn>();

            System.Text.RegularExpressions.Regex regx = new System.Text.RegularExpressions.Regex(@"\W");
            foreach (var column in featureLayerStructureParameters.AddedColumns)
            {
                FeatureSourceColumn newColumn = column;
                if (newColumn.ColumnName.Equals("Null", StringComparison.Ordinal))
                {
                    newColumn.ColumnName = "Null_";
                }
                newColumn.ColumnName = regx.Replace(newColumn.ColumnName, string.Empty);
                columns.Add(newColumn);
            }

            string tableName = string.Empty;

            if (featureLayerStructureParameters.CustomData.ContainsKey("TableName"))
            {
                //if (createFeatureLayerParameters.Tag != null)
                //tableName = createFeatureLayerParameters.Tag.ToString().Split('|').First();
                tableName = featureLayerStructureParameters.CustomData["TableName"] as string;
            }
            else
            {
                tableName = Path.GetFileNameWithoutExtension(featureLayerStructureParameters.LayerUri.OriginalString);
            }

            FileGeoDatabaseFeatureLayer.CreateFileGeoDatabase(featureLayerStructureParameters.LayerUri.OriginalString);
            FileGeoDatabaseFeatureLayer.CreateTable(featureLayerStructureParameters.LayerUri.OriginalString, tableName, featureLayerStructureParameters.WellKnownType, columns);

            string prjPath = Path.ChangeExtension(featureLayerStructureParameters.LayerUri.OriginalString, "prj");

            File.WriteAllText(prjPath, Proj4Projection.ConvertProj4ToPrj(featureLayerStructureParameters.Proj4ProjectionParametersString));

            FileGeoDatabaseFeatureLayer fileGeoDatabaseFeatureLayer = new FileGeoDatabaseFeatureLayer(featureLayerStructureParameters.LayerUri.LocalPath, tableName);

            if (featureLayerStructureParameters.AddedFeatures.Count > 0)
            {
                fileGeoDatabaseFeatureLayer.Open();
                fileGeoDatabaseFeatureLayer.EditTools.BeginTransaction();
                foreach (var feature in featureLayerStructureParameters.AddedFeatures)
                {
                    fileGeoDatabaseFeatureLayer.EditTools.Add(feature);
                }
                fileGeoDatabaseFeatureLayer.EditTools.CommitTransaction();
                fileGeoDatabaseFeatureLayer.Close();
            }

            return(fileGeoDatabaseFeatureLayer);
        }