public SpatialAnalysis(string globalShapeFileDataPath) { string dataPath = globalShapeFileDataPath; fsWorldCountries = FeatureSet.Open(dataPath); fsWorldCountries.Reproject(DotSpatial.Projections.KnownCoordinateSystems.Geographic.World.WGS1984); countryCodes = GetCountryCodeMappings(); }
/// <summary> /// Reprojects the specified vector layer. /// </summary> private IFeatureSet Reproject(IFeatureSet fsSource, ISpatialReference newProjection, string saveAsFilename) { int count; var fs = fsSource.Reproject(newProjection, out count); if (fs == null) { Logger.Current.Warn("Failed to reproject vector datasource: " + fsSource.LastError); return(null); } if (count == fsSource.Features.Count) { bool result = fs.SaveAs(saveAsFilename); if (!result) { Logger.Current.Warn("Failed to save reprojected shapefile: " + fs.LastError); fs.Close(); return(null); } Logger.Current.Info("Vector datasource is reprojected: " + saveAsFilename); return(fs); } Logger.Current.Warn("Not all features of the datasource were reprojected. The results are discarded."); fs.Close(); return(null); }
public SpatialAnalysis(string globalShapeFileDataPath) { System.Text.Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); string dataPath = globalShapeFileDataPath; fsWorldCountries = FeatureSet.Open(dataPath); fsWorldCountries.Reproject(DotSpatial.Projections.KnownCoordinateSystems.Geographic.World.WGS1984); countryCodes = GetCountryCodeMappings(); }
/// <summary> /// Executes the ReprojectFeatureSet Operation tool programmatically. /// </summary> /// <param name="featureSet">The input FeatureSet.</param> /// <param name="sourceProjection">The input Expression string to select features to Delete.</param> /// <param name="destProjection">The target projected coordinate system to reproject the featureset to</param> /// <param name="output">The output FeatureSet.</param> /// <param name="cancelProgressHandler">The progress handler.</param> /// <returns>True, if executed successfully.</returns> public bool Execute(IFeatureSet featureSet, ProjectionInfo sourceProjection, ProjectionInfo destProjection, IFeatureSet output, ICancelProgressHandler cancelProgressHandler) { string filename = output.Filename; output = featureSet.CopySubset(string.Empty); if (sourceProjection != null) { output.Projection = sourceProjection; } output.Reproject(destProjection); output.SaveAs(filename, true); return(true); }
/// <summary> /// This routine takes a DotSpatial Featureset and makes a clone and then reprojects it to the requested Projection. /// It returns a clone of the input so the input is not altered in any way. /// </summary> /// <param name="self">This featureSet.</param> /// <param name="targetPrj">The projection of the target clone FeatureSet.</param> /// <returns>A reprojected clone of the surce FeatureSet.</returns> public static IFeatureSet ReprojectedClone(this IFeatureSet self, ProjectionInfo targetPrj) { // input check if (self == null || targetPrj == null) { return(null); } self.FillAttributes(); IFeatureSet fsClone = self.CopyFeatures(true); fsClone.IndexMode = false; fsClone.Reproject(targetPrj); // success so return the reprojected clone FeatureSet return(fsClone); }
/// <summary> /// Executes the ReprojectFeatureSet Operation tool programaticaly. /// </summary> /// <param name="featureSet">The input FeatureSet.</param> /// <param name="sourceProjection">The input Expression string to select features to Delete.</param> /// <param name="destProjection">The target projected coordinate system to reproject the featureset to</param> /// <param name="output">The output FeatureSet.</param> /// <param name="cancelProgressHandler">The progress handler.</param> /// Ping deleted "static" for external testing /// <returns></returns> public bool Execute( IFeatureSet featureSet, ProjectionInfo sourceProjection, ProjectionInfo destProjection, IFeatureSet output, ICancelProgressHandler cancelProgressHandler) { output.CopyFeatures(featureSet, true); output.Projection = featureSet.Projection; if (sourceProjection != null) { output.Projection = sourceProjection; } output.Reproject(destProjection); output.SaveAs(output.Filename, true); return(true); }
/// <summary> /// Executes the ReprojectFeatureSet Operation tool programaticaly. /// </summary> /// <param name="featureSet">The input FeatureSet.</param> /// <param name="sourceProjection">The input Expression string to select features to Delete.</param> /// <param name="destProjection">The target projected coordinate system to reproject the featureset to</param> /// <param name="output">The output FeatureSet.</param> /// <param name="cancelProgressHandler">The progress handler.</param> /// Ping deleted "static" for external testing /// <returns></returns> public bool Execute(IFeatureSet featureSet, ProjectionInfo sourceProjection, ProjectionInfo destProjection, IFeatureSet output, ICancelProgressHandler cancelProgressHandler) { output.CopyFeatures(featureSet, true); output.Projection = featureSet.Projection; if(sourceProjection != null) output.Projection = sourceProjection; output.Reproject(destProjection); output.SaveAs(output.Filename, true); return true; }
public void TestSetViewExtents() { Map mainMap = new Map(); mainMap.Projection = KnownCoordinateSystems.Projected.World.WebMercator; Extent defaultMapExtent = new Extent(-130, 5, -70, 60); string baseMapFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestFiles"); //SetDefaultMapExtents(mainMap); MapPolygonLayer layStates; MapGroup baseGroup = new MapGroup(mainMap.Layers, mainMap.MapFrame, mainMap.ProgressHandler); baseGroup.LegendText = "Base Map Data"; baseGroup.ParentMapFrame = mainMap.MapFrame; baseGroup.MapFrame = mainMap.MapFrame; baseGroup.IsVisible = true; //load the 'Countries of the world' layer try { string fileName = Path.Combine(baseMapFolder, "50m_admin_0_countries.shp"); IFeatureSet fsCountries = FeatureSet.OpenFile(fileName); fsCountries.Reproject(mainMap.Projection); MapPolygonLayer layCountries = new MapPolygonLayer(fsCountries); layCountries.LegendText = "Countries"; PolygonScheme schmCountries = new PolygonScheme(); schmCountries.EditorSettings.StartColor = Color.Orange; schmCountries.EditorSettings.EndColor = Color.Silver; schmCountries.EditorSettings.ClassificationType = ClassificationType.UniqueValues; schmCountries.EditorSettings.FieldName = "NAME"; schmCountries.EditorSettings.UseGradient = true; schmCountries.CreateCategories(layCountries.DataSet.DataTable); layCountries.Symbology = schmCountries; baseGroup.Layers.Add(layCountries); layCountries.MapFrame = mainMap.MapFrame; } catch { } //load U.S. states layer try { string fileName = Path.Combine(baseMapFolder, "50mil_us_states.shp"); IFeatureSet fsStates = FeatureSet.OpenFile(fileName); fsStates.Reproject(mainMap.Projection); layStates = new MapPolygonLayer(fsStates); PolygonScheme schmStates = new PolygonScheme(); layStates.IsVisible = true; layStates.LegendText = "U.S. States"; schmStates.EditorSettings.StartColor = Color.LemonChiffon; schmStates.EditorSettings.EndColor = Color.LightPink; schmStates.EditorSettings.ClassificationType = ClassificationType.UniqueValues; schmStates.EditorSettings.FieldName = "NAME"; schmStates.EditorSettings.UseGradient = true; schmStates.CreateCategories(layStates.DataSet.DataTable); layStates.Symbology = schmStates; baseGroup.Layers.Add(layStates); layStates.MapFrame = mainMap.MapFrame; } catch { } //load Canada Provinces layer try { string fileName = Path.Combine(baseMapFolder, "50mil_canada_provinces.shp"); IFeatureSet fsProvince = FeatureSet.OpenFile(fileName); fsProvince.Reproject(mainMap.Projection); MapPolygonLayer layProvince = new MapPolygonLayer(fsProvince); PolygonScheme schmProvince = new PolygonScheme(); layProvince.IsVisible = true; layProvince.LegendText = "Canada Provinces"; schmProvince.EditorSettings.StartColor = Color.Green; schmProvince.EditorSettings.EndColor = Color.Yellow; schmProvince.EditorSettings.ClassificationType = ClassificationType.UniqueValues; schmProvince.EditorSettings.FieldName = "NAME"; schmProvince.EditorSettings.UseGradient = true; schmProvince.CreateCategories(layProvince.DataSet.DataTable); layProvince.Symbology = schmProvince; baseGroup.Layers.Add(layProvince); layProvince.MapFrame = mainMap.MapFrame; } catch { } //theme data group //create a new empty 'themes' data group try { MapGroup themeGroup = new MapGroup(mainMap.Layers, mainMap.MapFrame, mainMap.ProgressHandler); themeGroup.ParentMapFrame = mainMap.MapFrame; themeGroup.MapFrame = mainMap.MapFrame; themeGroup.LegendText = "Themes"; } catch { } double[] xy = new double[4]; xy[0] = defaultMapExtent.MinX; xy[1] = defaultMapExtent.MinY; xy[2] = defaultMapExtent.MaxX; xy[3] = defaultMapExtent.MaxY; double[] z = new double[] { 0, 0 }; string esri = "GEOGCS[\"GCS_WGS_1984\",DATUM[\"D_WGS_1984\",SPHEROID[\"WGS_1984\",6378137,298.257223562997]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.0174532925199433]]"; ProjectionInfo wgs84 = ProjectionInfo.FromEsriString(esri); Reproject.ReprojectPoints(xy, z, wgs84, mainMap.Projection, 0, 2); xy[0] = 1000000000000000; xy[1] = 2000000000000000; xy[2] = 3000000000000000; xy[3] = 4000000000000000; Extent ext = new Extent(xy); mainMap.ViewExtents = ext; }