@@ -33,12 +33,14 @@ public ImportOSMLite()
3333
3434 protected override void RegisterInputParams ( GH_Component . GH_InputParamManager pManager )
3535 {
36+ pManager . AddCurveParameter ( "Boundary" , "boundary" , "Boundary curve for vector data" , GH_ParamAccess . item ) ;
3637 pManager . AddTextParameter ( "OSM Data Location" , "filePath" , "File path for the OSM vector data input" , GH_ParamAccess . item ) ;
3738 pManager . AddTextParameter ( "Filter Fields" , "filterFields" , "List of filter terms for OSM fields such as highway, route, building, etc." , GH_ParamAccess . list ) ;
3839 pManager . AddTextParameter ( "Filter Field,Value" , "filterFieldValue" , "List of filter terms for OSM fields and values. Format Field,Value like 'addr:street,Main.'" , GH_ParamAccess . list ) ;
3940
40- pManager [ 1 ] . Optional = true ;
41+ pManager [ 0 ] . Optional = true ;
4142 pManager [ 2 ] . Optional = true ;
43+ pManager [ 3 ] . Optional = true ;
4244 }
4345
4446 /// <summary>
@@ -60,29 +62,31 @@ protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager
6062 protected override void SolveInstance ( IGH_DataAccess DA )
6163 {
6264 ///Gather GHA inputs
65+ Curve boundary = null ;
66+ DA . GetData < Curve > ( 0 , ref boundary ) ;
67+
6368 string osmFilePath = string . Empty ;
64- DA . GetData < string > ( 0 , ref osmFilePath ) ;
69+ DA . GetData < string > ( 1 , ref osmFilePath ) ;
6570
6671 List < string > filterWords = new List < string > ( ) ;
67- DA . GetDataList < string > ( 1 , filterWords ) ;
72+ DA . GetDataList < string > ( 2 , filterWords ) ;
6873
6974 List < string > filterKeyValue = new List < string > ( ) ;
70- DA . GetDataList < string > ( 2 , filterKeyValue ) ;
75+ DA . GetDataList < string > ( 3 , filterKeyValue ) ;
7176
72- Transform xformToMetric = new Transform ( 1 ) ;
73- Transform xformFromMetric = new Transform ( 1 ) ;
7477
7578 ///GDAL setup
7679 Heron . GdalConfiguration . ConfigureOgr ( ) ;
7780 Heron . GdalConfiguration . ConfigureGdal ( ) ;
7881
7982
80- ///Set transforms between OSM's WGS84 and Web Mercator which units are in meters
83+ ///Set transforms between OSM's WGS84 and Web Mercator to get x y units in meters
8184 OSGeo . OSR . SpatialReference osmSRS = new OSGeo . OSR . SpatialReference ( "" ) ;
8285 osmSRS . SetFromUserInput ( "WGS84" ) ;
8386 OSGeo . OSR . SpatialReference webMercator = new OSGeo . OSR . SpatialReference ( "" ) ;
8487 webMercator . SetFromUserInput ( "EPSG:3857" ) ;
8588 OSGeo . OSR . CoordinateTransformation coordTransform = new OSGeo . OSR . CoordinateTransformation ( osmSRS , webMercator ) ;
89+ OSGeo . OSR . CoordinateTransformation revTransform = new OSGeo . OSR . CoordinateTransformation ( webMercator , osmSRS ) ;
8690
8791
8892 ///Declare trees
@@ -95,6 +99,14 @@ protected override void SolveInstance(IGH_DataAccess DA)
9599
96100 Point3d max = new Point3d ( ) ;
97101 Point3d min = new Point3d ( ) ;
102+ if ( boundary != null )
103+ {
104+ Point3d maxM = boundary . GetBoundingBox ( true ) . Corner ( true , false , true ) ;
105+ max = Heron . Convert . OSRTransformPoint3dToPoint3d ( maxM , revTransform ) ;
106+
107+ Point3d minM = boundary . GetBoundingBox ( true ) . Corner ( false , true , true ) ;
108+ min = Heron . Convert . OSRTransformPoint3dToPoint3d ( minM , revTransform ) ;
109+ }
98110
99111 /// get extents (why is this not part of OsmSharp?)
100112 System . Xml . Linq . XDocument xdoc = System . Xml . Linq . XDocument . Load ( osmFilePath ) ;
@@ -120,11 +132,15 @@ protected override void SolveInstance(IGH_DataAccess DA)
120132 /// create a source.
121133 OsmSharp . Streams . XmlOsmStreamSource source = new OsmSharp . Streams . XmlOsmStreamSource ( fileStreamSource ) ;
122134
135+ /// filter by bounding box
136+ OsmSharp . Streams . OsmStreamSource sourceClipped = source ;
137+ if ( clipped ) { sourceClipped = source . FilterBox ( ( float ) max . X , ( float ) max . Y , ( float ) min . X , ( float ) min . Y , true ) ; }
138+
123139 /// create a dictionary of elements
124- OsmSharp . Db . Impl . MemorySnapshotDb sourceMem = new OsmSharp . Db . Impl . MemorySnapshotDb ( source ) ;
140+ OsmSharp . Db . Impl . MemorySnapshotDb sourceMem = new OsmSharp . Db . Impl . MemorySnapshotDb ( sourceClipped ) ;
125141
126142 /// filter the source
127- var filtered = from osmGeos in source
143+ var filtered = from osmGeos in sourceClipped
128144 where osmGeos . Tags != null
129145 select osmGeos ;
130146
@@ -246,9 +262,7 @@ where osmGeos.Tags.Intersect(tags).Any()
246262 ways = ways - 1 ;
247263 }
248264 else { buildingGoo . Append ( bldgGoo , waysPath ) ; }
249-
250265 }
251-
252266 }
253267
254268 //increment ways
@@ -318,9 +332,7 @@ where osmGeos.Tags.Intersect(tags).Any()
318332 {
319333 ///not sure if this is needed
320334 }
321-
322335 }
323-
324336 }
325337 //end members loop
326338
@@ -819,6 +831,53 @@ private static double GetMinBldgHeight(OsmSharp.OsmGeo osmGeo)
819831 return keyHeight ;
820832 }
821833
834+ /// <summary>
835+ /// Menu Items
836+ /// </summary>
837+
838+ private bool clipped = true ;
839+ public bool Clipped
840+ {
841+ get { return clipped ; }
842+ set
843+ {
844+ clipped = value ;
845+ if ( ( clipped ) )
846+ {
847+ Message = "Clipped" ;
848+ }
849+ else
850+ {
851+ Message = "Not Clipped" ;
852+ }
853+ }
854+ }
855+
856+ public override bool Write ( GH_IO . Serialization . GH_IWriter writer )
857+ {
858+ writer . SetBoolean ( "Clipped" , Clipped ) ;
859+ return base . Write ( writer ) ;
860+ }
861+ public override bool Read ( GH_IO . Serialization . GH_IReader reader )
862+ {
863+ Clipped = reader . GetBoolean ( "Clipped" ) ;
864+ return base . Read ( reader ) ;
865+ }
866+
867+ protected override void AppendAdditionalComponentMenuItems ( System . Windows . Forms . ToolStripDropDown menu )
868+ {
869+ // Append the item to the menu, making sure it's always enabled and checked if Absolute is True.
870+ ToolStripMenuItem item = Menu_AppendItem ( menu , "Clipped" , Menu_ClippedClicked , true , Clipped ) ;
871+ // Specifically assign a tooltip text to the menu item.
872+ item . ToolTipText = "When checked, the OSM data is clipped to the boundary input." ;
873+ }
874+ private void Menu_ClippedClicked ( object sender , EventArgs e )
875+ {
876+ RecordUndoEvent ( "Absolute" ) ;
877+ Clipped = ! Clipped ;
878+ ExpireSolution ( true ) ;
879+ }
880+
822881
823882 /// <summary>
824883 /// Provides an Icon for the component.
0 commit comments