Skip to content

Commit f839baf

Browse files
authored
Merge pull request #22 from nicoazel/ExportAttribute_Set_Your_Own_Type
Export attribute set your own type and new geojson exporters
2 parents 639096b + 2e214e3 commit f839baf

32 files changed

+694
-359
lines changed

.vs/BearGIS_Solution/v16/.suo

19 KB
Binary file not shown.

BearGIS/BearGIS.csproj

+18-12
Original file line numberDiff line numberDiff line change
@@ -125,24 +125,29 @@
125125
</Reference>
126126
</ItemGroup>
127127
<ItemGroup>
128+
<Compile Include="Converters\BuildJsonAttributes.cs" />
129+
<Compile Include="Converters\ReProjectCoordinates.cs" />
130+
<Compile Include="Converters\PtLongLat.cs" />
131+
<Compile Include="Exporters\PolylineJSON.cs" />
132+
<Compile Include="Exporters\PolygonJSON.cs" />
128133
<Compile Include="MyCategoryIcon.cs" />
129-
<Compile Include="LongLatPt.cs" />
130-
<Compile Include="ReadGeoJson.cs" />
131-
<Compile Include="PointJSON.cs" />
132-
<Compile Include="PolygonSHP.cs" />
133-
<Compile Include="PolylineSHP.cs" />
134-
<Compile Include="PointSHP.cs" />
135-
<Compile Include="ReadDotShp.cs" />
136-
<Compile Include="ReadShp.cs" />
137-
<Compile Include="PointESRI.cs" />
138-
<Compile Include="PolygonESRI.cs" />
134+
<Compile Include="Converters\LongLatPt.cs" />
135+
<Compile Include="Importers\ReadGeoJson.cs" />
136+
<Compile Include="Exporters\PointJSON.cs" />
137+
<Compile Include="Exporters\PolygonSHP.cs" />
138+
<Compile Include="Exporters\PolylineSHP.cs" />
139+
<Compile Include="Exporters\PointSHP.cs" />
140+
<Compile Include="Importers\ReadDotShp.cs" />
141+
<Compile Include="Importers\ReadShp.cs" />
142+
<Compile Include="Exporters\PointESRI.cs" />
143+
<Compile Include="Exporters\PolygonESRI.cs" />
139144
<Compile Include="Properties\Resources.Designer.cs">
140145
<AutoGen>True</AutoGen>
141146
<DesignTime>True</DesignTime>
142147
<DependentUpon>Resources.resx</DependentUpon>
143148
</Compile>
144-
<Compile Include="ReadESRIJson.cs" />
145-
<Compile Include="PolyLineESRI.cs" />
149+
<Compile Include="Importers\ReadESRIJson.cs" />
150+
<Compile Include="Exporters\PolyLineESRI.cs" />
146151
<Compile Include="BearGISInfo.cs" />
147152
<Compile Include="Properties\AssemblyInfo.cs" />
148153
</ItemGroup>
@@ -178,6 +183,7 @@
178183
<ItemGroup>
179184
<None Include="Resources\BearGISIconSet-20.png" />
180185
</ItemGroup>
186+
<ItemGroup />
181187
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
182188
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
183189
Other similar extension points exist, see Microsoft.Common.targets.

BearGIS/BearGIS.csproj.DotSettings

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
2+
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=importers/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

BearGIS/BearGISInfo.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ public override Bitmap Icon
1818
get
1919
{
2020
//Return a 24x24 pixel bitmap to represent this GHA library.
21-
return null;
21+
return BearGIS.Properties.Resources.BearGISIconSet_20;
2222
}
2323
}
2424
public override string Description
2525
{
2626
get
2727
{
2828
//Return a short string describing the purpose of this GHA library.
29-
return "";
29+
return "Bear GIS is a plugin for reading and writing gis data";
3030
}
3131
}
3232
public override Guid Id
@@ -42,15 +42,15 @@ public override string AuthorName
4242
get
4343
{
4444
//Return a string identifying you or your company.
45-
return "";
45+
return "Nicolas Azel";
4646
}
4747
}
4848
public override string AuthorContact
4949
{
5050
get
5151
{
5252
//Return a string representing your preferred contact details.
53-
return "";
53+
return "nico";
5454
}
5555
}
5656
}
+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
using System;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
5+
namespace BearGIS.Converters
6+
{
7+
public static class Converter
8+
{
9+
/// <summary>
10+
/// IList attributesBranch = attributes.get_Branch(path);
11+
///
12+
/// </summary>
13+
/// <param name="attributesBranch"></param>
14+
/// <returns></returns>
15+
public static Dictionary<string, object> BuildJsonAttributes(IList attributesBranch, List<string> fields)
16+
{
17+
//creat attriabtrues key
18+
Dictionary<string, object> thisAttribtues = new Dictionary<string, object>();
19+
20+
foreach (var item in attributesBranch)
21+
{
22+
string thisField = fields[attributesBranch.IndexOf(item)]; //fields are string
23+
24+
// ---------------------this is in order add the riight type?
25+
26+
if (item is Grasshopper.Kernel.Types.GH_Integer)
27+
{
28+
string thisAttribute = item.ToString();
29+
Convert.ChangeType(thisAttribute, typeof(int));
30+
thisAttribtues.Add(thisField, thisAttribute);
31+
}
32+
33+
else if (item is Grasshopper.Kernel.Types.GH_Number) // else if (typeItem is long //|| typeItem is ulong //|| typeItem is float //|| typeItem is double //|| typeItem is decimal)
34+
{
35+
string thisAttribute = item.ToString();
36+
Convert.ChangeType(thisAttribute, typeof(double));
37+
thisAttribtues.Add(thisField, thisAttribute);
38+
}
39+
40+
else if (item is Grasshopper.Kernel.Types.GH_String)
41+
{
42+
string thisAttribute = item.ToString();
43+
thisAttribtues.Add(thisField, thisAttribute);
44+
}
45+
46+
else if (item is Grasshopper.Kernel.Types.GH_Time)
47+
{
48+
string thisAttribute = item.ToString();
49+
Convert.ChangeType(thisAttribute, typeof(DateTime));
50+
thisAttribtues.Add(thisField, thisAttribute);
51+
}
52+
53+
else
54+
{
55+
string thisAttribute = "wasent a type"; item.ToString();
56+
thisAttribtues.Add(thisField, thisAttribute);
57+
}
58+
59+
// ------------------------how to add value of igh_goo verbatum....
60+
//thisAttribtues.Add(thisField, thisAttribute);
61+
}
62+
63+
return thisAttribtues;
64+
//return attributes;
65+
}
66+
}
67+
68+
}

BearGIS/LongLatPt.cs BearGIS/Converters/LongLatPt.cs

+2-12
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,18 @@
11
using System;
2-
using System.IO;
3-
using System.Linq;
4-
using System.Collections.Generic;
5-
6-
using GH_IO;
7-
using GH_IO.Serialization;
8-
using Grasshopper;
92
using Grasshopper.Kernel;
10-
using Grasshopper.Kernel.Data;
113
using Grasshopper.Kernel.Types;
12-
134
using Rhino.Geometry;
14-
155
using DotSpatial.Projections;
166

177
namespace BearGIS
188
{
199
public class LongLatPt : GH_Component
2010
{
2111
/// <summary>
22-
/// Initializes a new instance of the MyComponent1 class.
12+
/// Initializes a new instance of the PolygonJSON class.
2313
/// </summary>
2414
public LongLatPt()
25-
: base("LongLatPt", "LL-XY",
15+
: base("LongLatPT", "LL-XY",
2616
"This component provides the xy location of a given Lat Long coordinates and .Proj file of source coordinates",
2717
"BearGIS", "projection")
2818
{

BearGIS/Converters/PtLongLat.cs

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
using System;
2+
using Grasshopper.Kernel;
3+
using Grasshopper.Kernel.Types;
4+
5+
using Rhino.Geometry;
6+
7+
using DotSpatial.Projections;
8+
9+
namespace BearGIS
10+
{
11+
public class PtLongLat : GH_Component
12+
{
13+
/// <summary>
14+
/// Initializes a new instance of the PolygonJSON class.
15+
/// </summary>
16+
public PtLongLat()
17+
: base("PtLongLat", "XY-LL",
18+
"This component provides the lat lon location of a given X Y coordinates given the X Y .Proj file of source coordinates. Lat Lon are in KnownCoordinateSystems.Geographic.World.WGS1984",
19+
"BearGIS", "projection")
20+
{
21+
}
22+
23+
/// <summary>
24+
/// Registers all the input parameters for this component.
25+
/// </summary>
26+
protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
27+
{
28+
pManager.AddNumberParameter("X_Longatude", "XLong", "Longatude of desired xy point", GH_ParamAccess.item);
29+
pManager.AddNumberParameter("Y_Latatude", "YLat", "Latatude of desired xy point", GH_ParamAccess.item);
30+
pManager.AddTextParameter("PrjfilePath", "prj", "File Path of the.Proj File representing the source coordinate system", GH_ParamAccess.item);
31+
}
32+
33+
/// <summary>
34+
/// Registers all the output parameters for this component.
35+
/// </summary>
36+
protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)
37+
{
38+
pManager.AddPointParameter("point", "pt", "Point Coordinate of given longatude latatude", GH_ParamAccess.item);
39+
}
40+
41+
/// <summary>
42+
/// This is the method that actually does the work.
43+
/// </summary>
44+
/// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
45+
protected override void SolveInstance(IGH_DataAccess DA)
46+
{
47+
double lng = 0;
48+
double lat = 0;
49+
string fp = "";
50+
51+
if (!DA.GetData(0, ref lng)) return;
52+
if (!DA.GetData(1, ref lat)) return;
53+
if (!DA.GetData(2, ref fp)) return;
54+
55+
//load projection file
56+
string cur_proj = System.IO.File.ReadAllText(@fp);
57+
58+
///Starting projection
59+
ProjectionInfo sourceProjection = new ProjectionInfo();
60+
sourceProjection.ParseEsriString(cur_proj);
61+
62+
//ending projection
63+
ProjectionInfo targetProjection = KnownCoordinateSystems.Geographic.World.WGS1984;
64+
65+
int len = 1;
66+
double[] z = new double[] { 0 };
67+
double[] xy = new double[] { lng, lat };
68+
DotSpatial.Projections.Reproject.ReprojectPoints(xy, z, sourceProjection, targetProjection, 0, len);
69+
70+
Point3d rPt = new Point3d(xy[0], xy[1], z[0]);
71+
GH_Point pt = new GH_Point(rPt);
72+
73+
DA.SetData(0, pt);
74+
}
75+
76+
/// <summary>
77+
/// Provides an Icon for the component.
78+
/// </summary>
79+
protected override System.Drawing.Bitmap Icon
80+
{
81+
get
82+
{
83+
//You can add image files to your project resources and access them like this:
84+
return BearGIS.Properties.Resources.BearGISIconSet_17;
85+
// return Resources.IconForThisComponent;
86+
//return null;
87+
}
88+
}
89+
90+
/// <summary>
91+
/// Gets the unique ID for this component. Do not change this ID after release.
92+
/// </summary>
93+
public override Guid ComponentGuid
94+
{
95+
get { return new Guid("54D5D70B-A01A-4557-8285-6F94550D0890"); }
96+
}
97+
}
98+
}
+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
using System;
2+
using Grasshopper.Kernel;
3+
using Grasshopper.Kernel.Types;
4+
using Rhino.Geometry;
5+
using DotSpatial.Projections;
6+
7+
namespace BearGIS
8+
{
9+
public class ReProjectCoordinates : GH_Component
10+
{
11+
/// <summary>
12+
/// Initializes a new instance of the PolygonJSON class.
13+
/// </summary>
14+
public ReProjectCoordinates()
15+
: base("ReProject", "ReProj",
16+
"This component converts coordinates from one projection system to another",
17+
"BearGIS", "projection")
18+
{
19+
}
20+
21+
/// <summary>
22+
/// Registers all the input parameters for this component.
23+
/// </summary>
24+
protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
25+
{
26+
pManager.AddNumberParameter("X_Longatude", "XLong", "Longatude of desired xy point", GH_ParamAccess.item);
27+
pManager.AddNumberParameter("Y_Latatude", "YLat", "Latatude of desired xy point", GH_ParamAccess.item);
28+
pManager.AddTextParameter("SourcePrj", "SPrj", "File Path of the source projection '.Prj' File representing the source coordinate system", GH_ParamAccess.item);
29+
pManager.AddTextParameter("targetPrj", "TPprj", "File Path of the target projection '.Prj' File representing the target output coordinate system", GH_ParamAccess.item);
30+
}
31+
32+
/// <summary>
33+
/// Registers all the output parameters for this component.
34+
/// </summary>
35+
protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)
36+
{
37+
pManager.AddPointParameter("point", "pt", "Point Coordinate of given longatude latatude", GH_ParamAccess.item);
38+
}
39+
40+
/// <summary>
41+
/// This is the method that actually does the work.
42+
/// </summary>
43+
/// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
44+
protected override void SolveInstance(IGH_DataAccess DA)
45+
{
46+
double lng = 0;
47+
double lat = 0;
48+
string sourceFilePath = "";
49+
string targetFilePath = "";
50+
51+
if (!DA.GetData(0, ref lng)) return;
52+
if (!DA.GetData(1, ref lat)) return;
53+
if (!DA.GetData(2, ref sourceFilePath)) return;
54+
if (!DA.GetData(3, ref targetFilePath)) return;
55+
56+
//load projection file
57+
string cur_proj = System.IO.File.ReadAllText(@sourceFilePath);
58+
59+
///Starting projection
60+
ProjectionInfo sourceProjection = new ProjectionInfo();
61+
sourceProjection.ParseEsriString(cur_proj);
62+
63+
64+
//load projection file
65+
string tar_proj = System.IO.File.ReadAllText(@targetFilePath);
66+
//ending projection
67+
ProjectionInfo targetProjection = new ProjectionInfo();
68+
targetProjection.ParseEsriString(tar_proj);
69+
70+
int len = 1;
71+
double[] z = new double[] { 0 };
72+
double[] xy = new double[] { lng, lat };
73+
DotSpatial.Projections.Reproject.ReprojectPoints(xy, z, sourceProjection, targetProjection, 0, len);
74+
75+
Point3d rPt = new Point3d(xy[0], xy[1], z[0]);
76+
GH_Point pt = new GH_Point(rPt);
77+
78+
DA.SetData(0, pt);
79+
}
80+
81+
/// <summary>
82+
/// Provides an Icon for the component.
83+
/// </summary>
84+
protected override System.Drawing.Bitmap Icon
85+
{
86+
get
87+
{
88+
//You can add image files to your project resources and access them like this:
89+
return BearGIS.Properties.Resources.BearGISIconSet_17;
90+
// return Resources.IconForThisComponent;
91+
//return null;
92+
}
93+
}
94+
95+
/// <summary>
96+
/// Gets the unique ID for this component. Do not change this ID after release.
97+
/// </summary>
98+
public override Guid ComponentGuid
99+
{
100+
get { return new Guid("08C97FAF-71C3-4683-9F40-8289112E0D2D"); }
101+
}
102+
}
103+
}

0 commit comments

Comments
 (0)