/// <summary> /// Creates a new instance of Europe /// </summary> public Europe() { EMEP150KilometerGrid = new ProjectionInfo(); EMEP150KilometerGrid.ParseEsriString("PROJCS[\"EMEP_150_Kilometer_Grid\", GEOGCS[\"GCS_Sphere_EMEP\", DATUM[\"D_Sphere_EMEP\", SPHEROID[\"Sphere_EMEP\", 6370000.0, 0.0]], PRIMEM[\"Greenwich\", 0.0], UNIT[\"Degree\", 0.0174532925199433]], PROJECTION[\"Stereographic_North_Pole\"], PARAMETER[\"False_Easting\", 3.0], PARAMETER[\"False_Northing\", 37.0], PARAMETER[\"Central_Meridian\", -32.0], PARAMETER[\"Standard_Parallel_1\", 60.0], UNIT[\"150_Kilometers\", 150000.0]]"); EMEP50KilometerGrid = new ProjectionInfo(); EMEP50KilometerGrid.ParseEsriString("PROJCS[\"EMEP_50_Kilometer_Grid\", GEOGCS[\"GCS_Sphere_EMEP\", DATUM[\"D_Sphere_EMEP\", SPHEROID[\"Sphere_EMEP\", 6370000.0, 0.0]], PRIMEM[\"Greenwich\", 0.0], UNIT[\"Degree\", 0.0174532925199433]], PROJECTION[\"Stereographic_North_Pole\"], PARAMETER[\"False_Easting\", 8.0], PARAMETER[\"False_Northing\", 110.0], PARAMETER[\"Central_Meridian\", -32.0], PARAMETER[\"Standard_Parallel_1\", 60.0], UNIT[\"50_Kilometers\", 50000.0]]"); ETRS1989LAEA = ProjectionInfo.FromProj4String("+proj=laea +lat_0=52 +lon_0=10 +x_0=4321000 +y_0=3210000 +ellps=GRS80 +units=m +no_defs "); ETRS1989LCC = ProjectionInfo.FromProj4String("+proj=lcc +lat_1=35 +lat_2=65 +lat_0=52 +lon_0=10 +x_0=4000000 +y_0=2800000 +ellps=GRS80 +units=m +no_defs "); EuropeAlbersEqualAreaConic = ProjectionInfo.FromProj4String("+proj=aea +lat_1=43 +lat_2=62 +lat_0=30 +lon_0=10 +x_0=0 +y_0=0 +ellps=intl +units=m +no_defs "); EuropeEquidistantConic = ProjectionInfo.FromProj4String("+proj=eqdc +lat_0=0 +lon_0=0 +lat_1=43 +lat_2=62 +x_0=0 +y_0=0 +ellps=intl +units=m +no_defs "); EuropeLambertConformalConic = ProjectionInfo.FromProj4String("+proj=lcc +lat_1=43 +lat_2=62 +lat_0=30 +lon_0=10 +x_0=0 +y_0=0 +ellps=intl +units=m +no_defs "); EMEP50KilometerGrid.Name = "EMEP_50_Kilometer_Grid"; ETRS1989LAEA.Name = "ETRS_1989_LAEA"; ETRS1989LCC.Name = "ETRS_1989_LCC"; EuropeAlbersEqualAreaConic.Name = "Europe_Albers_Equal_Area_Conic"; EuropeEquidistantConic.Name = "Europe_Equidistant_Conic"; EuropeLambertConformalConic.Name = "Europe_Lambert_Conformal_Conic"; EMEP150KilometerGrid.GeographicInfo.Name = "GCS_Sphere_EMEP"; EMEP50KilometerGrid.GeographicInfo.Name = "GCS_Sphere_EMEP"; ETRS1989LAEA.GeographicInfo.Name = "GCS_ETRS_1989"; ETRS1989LCC.GeographicInfo.Name = "GCS_ETRS_1989"; EuropeAlbersEqualAreaConic.GeographicInfo.Name = "GCS_European_1950"; EuropeEquidistantConic.GeographicInfo.Name = "GCS_European_1950"; EuropeLambertConformalConic.GeographicInfo.Name = "GCS_European_1950"; EMEP150KilometerGrid.GeographicInfo.Datum.Name = "D_Sphere_EMEP"; EMEP50KilometerGrid.GeographicInfo.Datum.Name = "D_Sphere_EMEP"; ETRS1989LAEA.GeographicInfo.Datum.Name = "D_ETRS_1989"; ETRS1989LCC.GeographicInfo.Datum.Name = "D_ETRS_1989"; EuropeAlbersEqualAreaConic.GeographicInfo.Datum.Name = "D_European_1950"; EuropeEquidistantConic.GeographicInfo.Datum.Name = "D_European_1950"; EuropeLambertConformalConic.GeographicInfo.Datum.Name = "D_European_1950"; }
/// <summary> /// create a new instance of CRS from given esri WKT string /// </summary> public CRSData(string name, string esriString) { var prj = new ProjectionInfo(); prj.ParseEsriString(esriString); ProjectionInfo = prj; }
private static double[] Project(string projectionFilePath, double longitude, double latitude) { var srcProjection = KnownCoordinateSystems.Geographic.World.WGS1984; var destProjection = new ProjectionInfo(); var xy = new double[] { longitude, latitude }; var z = new double[] { 1 }; destProjection.ParseEsriString(File.ReadAllText(projectionFilePath)); Reproject.ReprojectPoints(xy, z, srcProjection, destProjection, 0, 1); return(xy); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { double lng = 0; double lat = 0; string fp = ""; if (!DA.GetData(0, ref lng)) { return; } if (!DA.GetData(1, ref lat)) { return; } if (!DA.GetData(2, ref fp)) { return; } //load projection file string cur_proj = System.IO.File.ReadAllText(@fp); ///Starting projection ProjectionInfo targetProjection = new ProjectionInfo(); targetProjection.ParseEsriString(cur_proj); //ending projection ProjectionInfo sourceProjection = KnownCoordinateSystems.Geographic.World.WGS1984; int len = 1; double[] z = new double[] { 0 }; double[] xy = new double[] { lng, lat }; DotSpatial.Projections.Reproject.ReprojectPoints(xy, z, sourceProjection, targetProjection, 0, len); Point3d rPt = new Point3d(xy[0], xy[1], z[0]); GH_Point pt = new GH_Point(rPt); DA.SetData(0, pt); }
private void BUT_shptopoly_Click(object sender, EventArgs e) { using (var fd = new OpenFileDialog()) { fd.Filter = "Shape file|*.shp"; var result = fd.ShowDialog(); var file = fd.FileName; var pStart = new ProjectionInfo(); var pESRIEnd = KnownCoordinateSystems.Geographic.World.WGS1984; var reproject = false; if (File.Exists(file)) { var prjfile = Path.GetDirectoryName(file) + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension(file) + ".prj"; if (File.Exists(prjfile)) { using ( var re = File.OpenText(Path.GetDirectoryName(file) + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension(file) + ".prj")) { pStart.ParseEsriString(re.ReadLine()); reproject = true; } } var fs = FeatureSet.Open(file); fs.FillAttributes(); var rows = fs.NumRows(); var dtOriginal = fs.DataTable; for (var row = 0; row < dtOriginal.Rows.Count; row++) { var original = dtOriginal.Rows[row].ItemArray; } foreach (DataColumn col in dtOriginal.Columns) { Console.WriteLine(col.ColumnName + " " + col.DataType); } var a = 1; var path = Path.GetDirectoryName(file); foreach (var feature in fs.Features) { var sb = new StringBuilder(); sb.Append("#Shap to Poly - Mission Planner\r\n"); foreach (var point in feature.Coordinates) { if (reproject) { double[] xyarray = { point.X, point.Y }; double[] zarray = { point.Z }; Reproject.ReprojectPoints(xyarray, zarray, pStart, pESRIEnd, 0, 1); point.X = xyarray[0]; point.Y = xyarray[1]; point.Z = zarray[0]; } sb.Append(point.Y.ToString(CultureInfo.InvariantCulture) + "\t" + point.X.ToString(CultureInfo.InvariantCulture) + "\r\n"); } log.Info("writting poly to " + path + Path.DirectorySeparatorChar + "poly-" + a + ".poly"); File.WriteAllText(path + Path.DirectorySeparatorChar + "poly-" + a + ".poly", sb.ToString()); a++; } } } }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { // First, we need to retrieve all data from the input parameters. List <string> fields = new List <string>(); GH_Structure <IGH_Goo> attributes = new GH_Structure <IGH_Goo>(); GH_Structure <GH_Point> inputPointTree = new GH_Structure <GH_Point>(); bool writeFile = false; string filePath = ""; string prj = null; if (!DA.GetData(5, ref writeFile)) { return; } if (!DA.GetData(4, ref filePath)) { return; } // access the input parameter by index. if (!DA.GetDataTree(0, out inputPointTree)) { return; } if (!DA.GetDataList(1, fields)) { return; } if (!DA.GetDataTree(2, out attributes)) { return; } if (!DA.GetData(3, ref prj)) { return; } //create new feature set to add data to //FeatureSet fs = new FeatureSet(FeatureType.Polygon); //FeatureSet fs = new FeatureSet(FeatureType.Point); FeatureSet fs = new FeatureSet(FeatureType.MultiPoint); if (prj != null) { //load projection file string cur_proj = System.IO.File.ReadAllText(@prj); ///create Projection system ProjectionInfo targetProjection = new ProjectionInfo(); targetProjection.ParseEsriString(cur_proj); fs.Projection = targetProjection; } if (writeFile) { // Add fields to the feature sets attribute table foreach (string field in fields) { //<<<dubble chack if this is properly declaring type>>>\\ fs.DataTable.Columns.Add(new DataColumn(field, typeof(string))); } // for every branch (ie feature) foreach (GH_Path path in inputPointTree.Paths) { //set branch IList branch = inputPointTree.get_Branch(path); // create a feature geometry List <Coordinate> vertices = new List <Coordinate>(); //add all pt coordinates to the vertices list foreach (GH_Point pt in branch) { Point3d rhinoPoint = new Point3d(); GH_Convert.ToPoint3d(pt, ref rhinoPoint, 0); vertices.Add(new Coordinate(rhinoPoint.X, rhinoPoint.Y)); } //Convert Coordinates to dot spatial point or multipoint geometry //DotSpatial.Topology.Point geom = new DotSpatial.Topology.Point(vertices); DotSpatial.Topology.MultiPoint geom = new DotSpatial.Topology.MultiPoint(vertices); //convert geom to a feature IFeature feature = fs.AddFeature(geom); //begin editing to add feature attributes feature.DataRow.BeginEdit(); //get this features attributes by its path IList <string> featrueAttributes = attributes.get_Branch(path) as IList <string>; int thisIndex = 0; //add each attribute for the pt's path foreach (var thisAttribute in attributes.get_Branch(path)) { //converting all fields to (((Proper Type...?))) feature.DataRow[fields[thisIndex]] = thisAttribute.ToString(); //currently everything is a string.... //<<<!!!!!!!!!! dubble chack if this is properly converting to the type declared above !!!!!!!!!!>>>\\ thisIndex++; } //finish attribute additions feature.DataRow.EndEdit(); }//end of itterating through branches of pt tree fs.SaveAs(filePath, true); } }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { // First, we need to retrieve all data from the input parameters. List <string> fields = new List <string>(); GH_Structure <IGH_Goo> attributes = new GH_Structure <IGH_Goo>(); GH_Structure <GH_Curve> inputPolylineTree = new GH_Structure <GH_Curve>(); bool writeFile = false; string filePath = ""; string prj = null; // access the input parameter by index. if (!DA.GetData(5, ref writeFile)) { return; } if (!DA.GetData(4, ref filePath)) { return; } if (!DA.GetDataTree(0, out inputPolylineTree)) { return; } if (!DA.GetDataList(1, fields)) { return; } if (!DA.GetDataTree(2, out attributes)) { return; } if (!DA.GetData(3, ref prj)) { return; } //create new feature set to add data to //FeatureSet fs = new FeatureSet(FeatureType.Polygon); //FeatureSet fs = new FeatureSet(FeatureType.Point); //FeatureSet fs = new FeatureSet(FeatureType.MultiPoint); FeatureSet fs = new FeatureSet(FeatureType.Line); if (prj != null) { //load projection file string cur_proj = System.IO.File.ReadAllText(@prj); ///create Projection system ProjectionInfo targetProjection = new ProjectionInfo(); targetProjection.ParseEsriString(cur_proj); fs.Projection = targetProjection; } if (writeFile) { // Add fields to the feature sets attribute table foreach (string field in fields) { //check for type string[] splitField = field.Split(';'); //if field type provided, specify it if (splitField.Length == 2) { fs.DataTable.Columns.Add(new DataColumn(splitField[0], Type.GetType(splitField[1]))); } else { //otherwise jsut use a string fs.DataTable.Columns.Add(new DataColumn(field, typeof(string))); } } // for every branch (ie feature) foreach (GH_Path path in inputPolylineTree.Paths) { //set branch IList branch = inputPolylineTree.get_Branch(path); List <DotSpatial.Topology.LineString> theseLines = new List <DotSpatial.Topology.LineString>(); foreach (GH_Curve curve in branch) { // create vertex list for this curve List <Coordinate> vertices = new List <Coordinate>(); //convert to rhino curve Curve rhinoCurve = null; GH_Convert.ToCurve(curve, ref rhinoCurve, 0); //curve to nurbes NurbsCurve thisNurbsCurve = rhinoCurve.ToNurbsCurve(); //Get list of control points Rhino.Geometry.Collections.NurbsCurvePointList theseControlPoints = thisNurbsCurve.Points; //for each control point foreach (ControlPoint thisPoint in theseControlPoints) { vertices.Add(new Coordinate(thisPoint.Location.X, thisPoint.Location.Y)); }//end each control point //create lineString Geometry from coordinates DotSpatial.Topology.LineString thisLine = new DotSpatial.Topology.LineString(vertices); // add linestring to linestring list theseLines.Add(thisLine); }//end curve itteration //Convert Coordinates to dot spatial point or multipoint geometry //DotSpatial.Topology.Point geom = new DotSpatial.Topology.Point(vertices); //DotSpatial.Topology.MultiPoint geom = new DotSpatial.Topology.MultiPoint(vertices); //convert list of line strings into single multilinestring feature MultiLineString geom = new MultiLineString(theseLines); //convert geom to a feature IFeature feature = fs.AddFeature(geom); //begin editing to add feature attributes feature.DataRow.BeginEdit(); //get this features attributes by its path IList <string> featrueAttributes = attributes.get_Branch(path) as IList <string>; int thisIndex = 0; //add each attribute for the pt's path foreach (var thisAttribute in attributes.get_Branch(path)) { string thisField = fields[thisIndex].Split(';')[0]; feature.DataRow[thisField] = thisAttribute.ToString(); //currently everything is a string.... thisIndex++; } //finish attribute additions feature.DataRow.EndEdit(); }//end of itterating through branches of pt tree fs.SaveAs(filePath, true); } }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { // First, we need to retrieve all data from the input parameters. List <string> fields = new List <string>(); GH_Structure <IGH_Goo> attributes = new GH_Structure <IGH_Goo>(); GH_Structure <GH_Curve> inputPolygonTree = new GH_Structure <GH_Curve>(); bool writeFile = false; string filePath = ""; string prj = null; // access the input parameter by index. if (!DA.GetData(5, ref writeFile)) { return; } if (!DA.GetData(4, ref filePath)) { return; } if (!DA.GetDataTree(0, out inputPolygonTree)) { return; } if (!DA.GetDataList(1, fields)) { return; } if (!DA.GetDataTree(2, out attributes)) { return; } if (!DA.GetData(3, ref prj)) { return; } //create new feature set to add data to FeatureSet fs = new FeatureSet(FeatureType.Polygon); //FeatureSet fs = new FeatureSet(FeatureType.Point); //FeatureSet fs = new FeatureSet(FeatureType.MultiPoint); //FeatureSet fs = new FeatureSet(FeatureType.Line); if (prj != null) { //load projection file string cur_proj = System.IO.File.ReadAllText(@prj); ///create Projection system ProjectionInfo targetProjection = new ProjectionInfo(); targetProjection.ParseEsriString(cur_proj); fs.Projection = targetProjection; } if (writeFile) { // Add fields to the feature sets attribute table foreach (string field in fields) { //<<<dubble chack if this is properly declaring type>>>\\ fs.DataTable.Columns.Add(new DataColumn(field, typeof(string))); } // for every branch (ie feature) foreach (GH_Path path in inputPolygonTree.Paths) { //set branch IList branch = inputPolygonTree.get_Branch(path); //List<DotSpatial.Topology.LineString> theseLines = new List<DotSpatial.Topology.LineString>(); List <LinearRing> theseCurves = new List <LinearRing>(); foreach (GH_Curve curve in branch) { // create vertex list for this curve List <Coordinate> vertices = new List <Coordinate>(); //convert to rhino curve Curve rhinoCurve = null; GH_Convert.ToCurve(curve, ref rhinoCurve, 0); //curve to nurbes NurbsCurve thisNurbsCurve = rhinoCurve.ToNurbsCurve(); //Get list of control points Rhino.Geometry.Collections.NurbsCurvePointList theseControlPoints = thisNurbsCurve.Points; //for each control point foreach (ControlPoint thisPoint in theseControlPoints) { vertices.Add(new Coordinate(thisPoint.Location.X, thisPoint.Location.Y)); }//end each control point //create linering Geometry from coordinates LinearRing thisCurve = new LinearRing(vertices); // add curve to curve list theseCurves.Add(thisCurve); }//end curve itteration //Convert Coordinates to dot spatial point or multipoint geometry //DotSpatial.Topology.Point geom = new DotSpatial.Topology.Point(vertices); //DotSpatial.Topology.MultiPoint geom = new DotSpatial.Topology.MultiPoint(vertices); DotSpatial.Topology.ILinearRing outerCurve = theseCurves[0]; var innerCurves = theseCurves.GetRange(1, theseCurves.Count - 1).ToArray(); //convert list of line strings into single multilinestring feature //MultiLineString geom = new MultiLineString(theseLines); Polygon geom = new Polygon(outerCurve, innerCurves); //convert geom to a feature IFeature feature = fs.AddFeature(geom); //begin editing to add feature attributes feature.DataRow.BeginEdit(); //get this features attributes by its path IList <string> featrueAttributes = attributes.get_Branch(path) as IList <string>; int thisIndex = 0; //add each attribute for the pt's path foreach (var thisAttribute in attributes.get_Branch(path)) { //converting all fields to (((Proper Type...?))) feature.DataRow[fields[thisIndex]] = thisAttribute.ToString(); //currently everything is a string.... //<<<!!!!!!!!!! dubble chack if this is properly converting to the type declared above !!!!!!!!!!>>>\\ thisIndex++; } //finish attribute additions feature.DataRow.EndEdit(); }//end of itterating through branches of pt tree fs.SaveAs(filePath, true); } }