}//误点 private void button1_Click(object sender, EventArgs e) { //define the projections map1.Projection = KnownCoordinateSystems.Projected.UtmNad1983.NAD1983UTMZone12N; map2.Projection = KnownCoordinateSystems.Projected.NorthAmerica.NorthAmericaAlbersEqualAreaConic; map3.Projection = KnownCoordinateSystems.Projected.NorthAmerica.USAContiguousLambertConformalConic; map4.Projection = KnownCoordinateSystems.Projected.World.CylindricalEqualAreaworld; map5.Projection = KnownCoordinateSystems.Projected.Polar.NorthPoleAzimuthalEquidistant; map6.Projection = KnownCoordinateSystems.Projected.NorthAmerica.USAContiguousAlbersEqualAreaConicUSGS; //add the layers OpenFileDialog fileDialog = new OpenFileDialog(); fileDialog.Filter = "Shapefiles|*.shp"; if (fileDialog.ShowDialog() == DialogResult.OK) { //add layer to first map FeatureSet featureSet1 = new FeatureSet(); featureSet1.Open(fileDialog.FileName); //Populate the FiledName dropdownlist with the help of featureset1. //We need to pass featureset as an input paramter to FillColumnNames method. FillColumnNames(featureSet1); //set the projection featureSet1.Reproject(map1.Projection); map1.Layers.Add(featureSet1); //add layer to second map FeatureSet featureSet2 = new FeatureSet(); featureSet2.Open(fileDialog.FileName); featureSet2.Reproject(map2.Projection); map2.Layers.Add(featureSet2); //add layer to map3 FeatureSet featureSet3 = new FeatureSet(); featureSet3.Open(fileDialog.FileName); featureSet3.Reproject(map3.Projection); map3.Layers.Add(featureSet3); //add layer to map4 FeatureSet featureSet4 = new FeatureSet(); featureSet4.Open(fileDialog.FileName); featureSet4.Reproject(map4.Projection); map4.Layers.Add(featureSet4); //add layer to map5 FeatureSet featureSet5 = new FeatureSet(); featureSet5.Open(fileDialog.FileName); featureSet5.Reproject(map5.Projection); map5.Layers.Add(featureSet5); //add layer to map6 FeatureSet featureSet6 = new FeatureSet(); featureSet6.Open(fileDialog.FileName); featureSet6.Reproject(map6.Projection); map6.Layers.Add(featureSet6); } }//误点
public static List <IFeature> ReprojectPolygonsToWGS84(FeatureSet polygons) { if (polygons == null) { throw new ArgumentNullException("polygons"); } polygons.Reproject(_wgs84Projection); return(Enumerable.ToList(polygons.Features)); }
public static IGeometry Project(IGeometry geometry, ProjectionInfo pStart, ProjectionInfo pEnd) { var featureSet = new FeatureSet(); featureSet.AddFeature(geometry.ToDotSpatial()); featureSet.Projection = pStart; featureSet.Reproject(pEnd); return (GeometryConverter.ToGeoAPI( ((featureSet.Features[0].BasicGeometry as DotSpatial.Topology.IGeometry)))); }
/// <summary> /// Get X,Y axis expressed by longitude and latitude /// </summary> /// <returns>mat[2][], mat[0] is longitude, mat[1] is latitude </returns> public float[][] GetLonLatAxis() { var lonlat = new float[2][]; lonlat[0] = new float[ColumnCount]; lonlat[1] = new float[RowCount]; var wgs84 = ProjectionInfo.FromEpsgCode(4326); IFeatureSet fs_lon = new FeatureSet(FeatureType.Point); fs_lon.Projection = this.Projection; for (int c = 0; c < ColumnCount; c++) { var vertice = LocateCentroid(c + 1, 1); Point pt = new Point(vertice); fs_lon.AddFeature(pt); } if (fs_lon.Projection != null) { fs_lon.Reproject(wgs84); } for (int c = 0; c < ColumnCount; c++) { var fea = fs_lon.GetFeature(c).Geometry.Coordinate; lonlat[0][c] = (float)fea.X; } IFeatureSet fs_lat = new FeatureSet(FeatureType.Point); fs_lat.Projection = this.Projection; for (int r = 0; r < RowCount; r++) { var vertice = LocateCentroid(1, r + 1); Point pt = new Point(vertice); fs_lat.AddFeature(pt); } if (fs_lat.Projection != null) { fs_lat.Reproject(wgs84); } for (int r = 0; r < RowCount; r++) { var fea = fs_lat.GetFeature(r).Geometry.Coordinate; lonlat[1][r] = (float)fea.Y; } return(lonlat); }
public static System.Data.Entity.Spatial.DbGeometry Project(System.Data.Entity.Spatial.DbGeometry source, ProjectionInfo pStart, ProjectionInfo pEnd) { var wkt = source.WellKnownValue.WellKnownText; var wktReader = new WKTReader(); var geometry = wktReader.Read(wkt); var featureSet = new FeatureSet(); featureSet.Features.Add(geometry.ToDotSpatial()); featureSet.Projection = pStart; featureSet.Reproject(pEnd); var projected = (featureSet.Features.First().BasicGeometry as IGeometry).ToGeoAPI(); var wktWriter = new WKTWriter(); var projectedWkt = wktWriter.Write(projected); return(System.Data.Entity.Spatial.DbGeometry.FromText(projectedWkt)); }
public static List <IGeometry> Project(List <IGeometry> toList, ProjectionInfo pStart, ProjectionInfo pEnd) { var geometryCollection = new GeometryCollection(toList.ToArray()); var collection = geometryCollection.ToDotSpatial(); var featureSet = new FeatureSet(); foreach (var geo in collection.Geometries) { featureSet.Features.Add(geo); } featureSet.Projection = pStart; featureSet.Reproject(pEnd); var dotSpatialProjectedGeos = featureSet.Features.Select(x => x.BasicGeometry as DotSpatial.Topology.IGeometry).ToList(); var result = dotSpatialProjectedGeos.Select( dotSpatialProjectedGeo => GeometryConverter.ToGeoAPI((dotSpatialProjectedGeo))) .ToList(); return(result); }
private void button2_Click(object sender, EventArgs e) { // Iterate through each properties of shapefiles foreach (CropProperties property in _properties) { // Test if checked or not foreach (ListViewItem item in listView1.CheckedItems) { if (item.Text.Contains(property.shp.Name)) { // Get original shapefile and reproject to WGS84 Shapefile file = property.shp; ProjectionInfo originalPrj = file.Projection; ProjectionInfo WGS84 = ProjectionInfo.FromProj4String(KnownCoordinateSystems.Geographic.World.WGS1984.ToProj4String()); file.Reproject(WGS84); // Create new shapefile & set projection FeatureSet result = new FeatureSet(FeatureType.Polygon); result.Projection = file.Projection; // Set new extent Extent extent = new Extent(); extent.SetValues(property.minCrop.Lng, property.minCrop.Lat, property.maxCrop.Lng, property.maxCrop.Lat); // Copy feature data result.CopyTableSchema(file); foreach (Feature f in file.Features) { // Test to see if coord is within extent Shape shp = f.ToShape(); IGeometry geom = shp.ToGeometry(); IList <Coordinate> coords = geom.Coordinates; int hit = 0; foreach (Coordinate coord in coords) { if (extent.Contains(coord)) { hit++; } else { continue; } } if (hit != 0) { // Iterate through coords in list Polygon poly = new Polygon(coords); result.AddFeature(poly).CopyAttributes(f); } else { continue; } } // Project pts back to original and save result.Reproject(originalPrj); if (property.path.Contains(".shp")) { result.SaveAs(property.path, true); } else { result.SaveAs(property.path + ".shp", true); } } } } this.Close(); }