5353for i in range (len (projNames )):
5454 projDict [i ] = projNames [i ]
5555
56-
5756def applyAttributesFromVCStmpl (tmpl , tmplattribute , txtobj = None ):
5857 tatt = getattr (tmpl , tmplattribute )
5958 if txtobj is None :
@@ -93,10 +92,6 @@ def putMaskOnVTKGrid(data, grid, actorColor=None, cellData=True, deep=True):
9392 grid2 .GetPointData ().RemoveArray (
9493 vtk .vtkDataSetAttributes .GhostArrayName ())
9594 grid2 .GetPointData ().SetScalars (imsk )
96- # grid2.SetCellVisibilityArray(imsk)
97- # p2c = vtk.vtkPointDataToCellData()
98- # p2c.SetInputData(grid2)
99- # geoFilter.SetInputConnection(p2c.GetOutputPort())
10095 geoFilter .SetInputData (grid2 )
10196 lut .SetTableValue (0 , r / 100. , g / 100. , b / 100. , 1. )
10297 lut .SetTableValue (1 , r / 100. , g / 100. , b / 100. , 1. )
@@ -137,9 +132,7 @@ def handleProjectionEdgeCases(projection, data):
137132 # For mercator projection, latitude values of -90 or 90
138133 # transformation result in infinity values. We chose -85, 85
139134 # as that's the typical limit used by the community.
140-
141135 pname = projDict .get (projection ._type , projection .type )
142-
143136 if (pname .lower () == "merc" ):
144137 lat = data .getLatitude ()[:]
145138 # Reverse the latitudes incase the starting latitude is greater
@@ -149,14 +142,16 @@ def handleProjectionEdgeCases(projection, data):
149142 data = data (latitude = (max (- 85 , lat .min ()), min (85 , lat .max ())))
150143 return data
151144
152-
153- def genGridOnPoints ( data1 , gm , deep = True , grid = None , geo = None ):
145+ def genGridOnPoints ( data1 , gm , deep = True , grid = None , geo = None ,
146+ skipReprojection = False , data2 = None ):
154147 continents = False
155148 projection = vcs .elements ["projection" ][gm .projection ]
156149 xm , xM , ym , yM = None , None , None , None
157150 useStructuredGrid = True
158151
159152 data1 = handleProjectionEdgeCases (projection , data1 )
153+ if data2 is not None :
154+ data2 = handleProjectionEdgeCases (projection , data2 )
160155
161156 try :
162157 g = data1 .getGrid ()
@@ -207,23 +202,25 @@ def genGridOnPoints(data1, gm, deep=True, grid=None, geo=None):
207202 m3 = numpy .concatenate ((m3 , z ), axis = 1 )
208203 deep = True
209204 pts = vtk .vtkPoints ()
205+ pts .SetDataTypeToDouble ()
210206 # Convert nupmy array to vtk ones
211207 ppV = numpy_to_vtk_wrapper (m3 , deep = deep )
212208 pts .SetData (ppV )
213209 else :
214210 xm , xM , ym , yM , tmp , tmp2 = grid .GetPoints ().GetBounds ()
215211 vg = grid
216212 xm , xM , ym , yM = getRange (gm , xm , xM , ym , yM )
217- if geo is None :
213+ if geo is None and not skipReprojection :
218214 geo , geopts = project (pts , projection , [xm , xM , ym , yM ])
215+ pts = geopts
219216 # Sets the vertices into the grid
220217 if grid is None :
221218 if useStructuredGrid :
222219 vg = vtk .vtkStructuredGrid ()
223220 vg .SetDimensions (data1 .shape [1 ], data1 .shape [0 ], 1 )
224221 else :
225222 vg = vtk .vtkUnstructuredGrid ()
226- vg .SetPoints (geopts )
223+ vg .SetPoints (pts )
227224 else :
228225 vg = grid
229226 out = {"vtk_backend_grid" : vg ,
@@ -234,7 +231,8 @@ def genGridOnPoints(data1, gm, deep=True, grid=None, geo=None):
234231 "continents" : continents ,
235232 "wrap" : wrap ,
236233 "geo" : geo ,
237- "data" : data1
234+ "data" : data1 ,
235+ "data2" : data2
238236 }
239237 return out
240238
@@ -545,6 +543,38 @@ def prepContinents(fnm):
545543 vcsContinents [fnm ] = poly
546544 return poly
547545
546+ def projectArray (w , projection , geo = None ):
547+ if isinstance (projection , (str , unicode )):
548+ projection = vcs .elements ["projection" ][projection ]
549+ if projection .type == "linear" :
550+ return None , pts
551+
552+ if geo is None :
553+ geo = vtk .vtkGeoTransform ()
554+ ps = vtk .vtkGeoProjection ()
555+ pd = vtk .vtkGeoProjection ()
556+
557+ pname = projDict .get (projection ._type , projection .type )
558+ projName = pname
559+ pd .SetName (projName )
560+
561+ if projection .type == "polar (non gctp)" :
562+ if ym < yM :
563+ pd .SetOptionalParameter ("lat_0" , "-90." )
564+ pd .SetCentralMeridian (xm )
565+ else :
566+ pd .SetOptionalParameter ("lat_0" , "90." )
567+ pd .SetCentralMeridian (xm + 180. )
568+ else :
569+ setProjectionParameters (pd , projection )
570+ geo .SetSourceProjection (ps )
571+ geo .SetDestinationProjection (pd )
572+
573+ for i in range (0 , w .GetNumberOfTuples ()):
574+ tuple = [0 , 0 , 0 ]
575+ w .GetTupleValue (i , tuple )
576+ geo .TransformPoint (tuple , tuple )
577+ w .SetTupleValue (i , tuple )
548578
549579# Geo projection
550580def project (pts , projection , wc , geo = None ):
@@ -573,6 +603,7 @@ def project(pts, projection, wc, geo=None):
573603 geo .SetSourceProjection (ps )
574604 geo .SetDestinationProjection (pd )
575605 geopts = vtk .vtkPoints ()
606+ geopts .SetDataTypeToDouble ()
576607 geo .TransformPoints (pts , geopts )
577608 return geo , geopts
578609
0 commit comments