//temporary, for use generating a shape file for each huc 8 private void button8_Click(object sender, EventArgs e) { filePath = ""; filePath = textBox1.Text; if (filePath == "") { MessageBox.Show("Please select a file path"); return; } //export rectangle as shapefile Boolean overwrite = true; FeatureSet copy = null; FeatureSet fs = (FeatureSet)map.Layers[map.Layers.Count - 1].DataSet; List <IFeature> featureList = null; //identify selected watershed and export as shapefile foreach (IFeatureLayer item2 in map.GetFeatureLayers()) { try { IFeatureLayer ifea = item2 as IFeatureLayer; if (ifea.Selection.Count > 0) { ifea.SelectAll(); featureList = ifea.Selection.ToFeatureList(); } } catch { } } if (fs == null && copy == null) { MessageBox.Show("Please select a feature on the map or draw a region"); return; } for (int i = 0; i < featureList.Count; i++) { //save shape file IFeature ifea = featureList[i]; IFeature ifea2 = ifea.Centroid(); IList <DotSpatial.Topology.Coordinate> centroid = ifea2.Coordinates; System.IO.Directory.CreateDirectory(filePath + "\\" + i); string newFilePath = filePath + "\\" + i + "\\" + "a" + centroid[0].X + "_" + centroid[0].Y + ".shp"; fs = new FeatureSet(); fs.AddFeature(ifea); fs.SaveAs(newFilePath, overwrite); //modify shape file // Compose a string consisting of EPSG WKT for web mercator string lines = "PROJCS[\"WGS 84 / Pseudo-Mercator\",\r\n GEOGCS[\"WGS 84\",\r\n DATUM[\"World Geodetic System 1984\",\r\n SPHEROID[\"WGS 84\", 6378137.0, 298.257223563, AUTHORITY[\"EPSG\",\"7030\"]],\r\n AUTHORITY[\"EPSG\",\"6326\"]],\r\n PRIMEM[\"Greenwich\", 0.0, AUTHORITY[\"EPSG\",\"8901\"]],\r\n UNIT[\"degree\", 0.017453292519943295],\r\n AXIS[\"Geodetic longitude\", EAST],\r\n AXIS[\"Geodetic latitude\", NORTH],\r\n AUTHORITY[\"EPSG\",\"4326\"]],\r\n PROJECTION[\"Popular Visualisation Pseudo Mercator\", AUTHORITY[\"EPSG\",\"1024\"]],\r\n PARAMETER[\"semi_minor\", 6378137.0],\r\n PARAMETER[\"latitude_of_origin\", 0.0],\r\n PARAMETER[\"central_meridian\", 0.0],\r\n PARAMETER[\"scale_factor\", 1.0],\r\n PARAMETER[\"false_easting\", 0.0],\r\n PARAMETER[\"false_northing\", 0.0],\r\n UNIT[\"m\", 1.0],\r\n AXIS[\"Easting\", EAST],\r\n AXIS[\"Northing\", NORTH],\r\n AUTHORITY[\"EPSG\",\"3857\"]]"; // Write the string to the .prj file newFilePath = newFilePath.Remove(newFilePath.Length - 3) + "prj"; System.IO.StreamWriter file = new System.IO.StreamWriter(newFilePath); file.WriteLine(lines); file.Close(); } this.Hide(); }