Skip to content

Commit

Permalink
remove shapely from export functions
Browse files Browse the repository at this point in the history
  • Loading branch information
changliao1025 committed Oct 16, 2023
1 parent 72727ba commit d3468a7
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 16 deletions.
4 changes: 3 additions & 1 deletion pyflowline/classes/_visual_basin.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def basin_plot(self,
iFlag_title_in=None,
iFlag_colorbar_in=None,
iFlag_scientific_notation_colorbar_in=None,
iFlag_openstreetmap_in = None,
dData_min_in = None,
dData_max_in = None,
sVariable_in=None,
Expand Down Expand Up @@ -104,7 +105,8 @@ def basin_plot(self,
map_multiple_vector_data(aFiletype_in,
aFilename_in,
iFlag_title_in=iFlag_title_in,
iFont_size_in=iFont_size_in,
iFont_size_in=iFont_size_in,
iFlag_openstreetmap_in=iFlag_openstreetmap_in,
sFilename_output_in=sFilename_output_in,
sTitle_in= 'Flow direction with observation',
aFlag_thickness_in= [1, 0, 0],
Expand Down
2 changes: 1 addition & 1 deletion pyflowline/classes/tin.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def which_edge_cross_this_vertex(self, pVertex_in):
return iFlag_found, pEdge_out

def calculate_cell_area(self):
self.dArea = 0.0
#self.dArea = 0.0
return self.dArea

def calculate_edge_length(self):
Expand Down
19 changes: 16 additions & 3 deletions pyflowline/external/pyearth/visual/map/map_multiple_vector_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ def map_multiple_vector_data(aFiletype_in,
aVariable_in = None,
sFilename_output_in=None,
iFlag_scientific_notation_colorbar_in=None,
iFlag_openstreetmap_in = None,
iFont_size_in=None,
iFlag_openstreetmap_level_in = None,
sColormap_in = None,
sTitle_in = None,
iDPI_in = None,
Expand Down Expand Up @@ -239,7 +241,7 @@ def map_multiple_vector_data(aFiletype_in,
ax = fig.add_axes([0.08, 0.1, 0.62, 0.7], projection= pProjection_map ) #projection=ccrs.PlateCarree()

# Create an OSM image tile source
osm_tiles = OSM()


if aExtent_in is None:
marginx = (dLon_max - dLon_min) / 50
Expand All @@ -250,8 +252,19 @@ def map_multiple_vector_data(aFiletype_in,

ax.set_global()
ax.set_extent( aExtent )
#Add the OSM image to the map
ax.add_image(osm_tiles, 9)
if iFlag_openstreetmap_in is not None:
if iFlag_openstreetmap_level_in is not None:
iFlag_openstreetmap_level = iFlag_openstreetmap_level_in
else:
iFlag_openstreetmap_level = 9
pass

osm_tiles = OSM()
#Add the OSM image to the map
ax.add_image(osm_tiles, iFlag_openstreetmap_level)
sLicense_info = "© OpenStreetMap contributors, CC-BY-SA"
ax.text(0.5, 0.05, sLicense_info, transform=ax.transAxes, ha='center', va='center', fontsize=10, color='gray', bbox=dict(facecolor='white', edgecolor='black', boxstyle='round,pad=0.3'))



#====================================
Expand Down
16 changes: 10 additions & 6 deletions pyflowline/formats/export_flowline.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import json
from osgeo import ogr, osr
from shapely.geometry import Point, LineString
#from shapely.geometry import Point, LineString
from pyflowline.classes.edge import pyedge
from pyflowline.classes.link import pycelllink

Expand Down Expand Up @@ -81,17 +81,21 @@ def export_flowline_to_geojson( aFlowline_in,
for i in range(nFlowline):
pFlowline = aFlowline_in[i]
dummy =pFlowline.aVertex
aPoint=list()
#replace shapely with gdal function
#aPoint=list()
pLine = ogr.Geometry(ogr.wkbLineString)
for j in dummy:
if iFlag_projected_in ==1:
aPoint.append( Point( j.dx, j.dy ) )
#aPoint.append( Point( j.dx, j.dy ) )
pLine.AddPoint(j.dx, j.dy)
pass
else:
aPoint.append( Point( j.dLongitude_degree, j.dLatitude_degree ) )
#aPoint.append( Point( j.dLongitude_degree, j.dLatitude_degree ) )
pLine.AddPoint(j.dLongitude_degree, j.dLatitude_degree)
pass

dummy1= LineString( aPoint )
pGeometry_out = ogr.CreateGeometryFromWkb(dummy1.wkb)
#dummy1= LineString( aPoint )
pGeometry_out = ogr.CreateGeometryFromWkb(pLine.ExportToWkb())
pFeature_out.SetGeometry(pGeometry_out)

pFeature_out.SetField("lineid", lID)
Expand Down
12 changes: 8 additions & 4 deletions pyflowline/formats/export_vertex.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
from osgeo import ogr, osr
from shapely.geometry import Point
#from shapely.geometry import Point

def export_vertex_to_geojson(aVertex_in,
sFilename_json_in,
Expand Down Expand Up @@ -56,14 +56,18 @@ def export_vertex_to_geojson(aVertex_in,
lID = 0
for i in range(nVertex):
pVertex = aVertex_in[i]
pPoint = ogr.Geometry(ogr.wkbPoint)
if iFlag_projected_in ==1:
dummy1= Point( pVertex.dx, pVertex.dy )
#dummy1= Point( pVertex.dx, pVertex.dy )
pPoint.AddPoint(pVertex.dx, pVertex.dy)
pass
else:
dummy1= Point( pVertex.dLongitude_degree, pVertex.dLatitude_degree )
#dummy1= Point( pVertex.dLongitude_degree, pVertex.dLatitude_degree )
pPoint.AddPoint(pVertex.dLongitude_degree, pVertex.dLatitude_degree)
pass

pGeometry_out = ogr.CreateGeometryFromWkb(dummy1.wkb)

pGeometry_out = ogr.CreateGeometryFromWkb(pPoint.ExportToWkb())
pFeature_out.SetGeometry(pGeometry_out)
pFeature_out.SetField("pointid", lID)
if iFlag_attribute ==1:
Expand Down
2 changes: 1 addition & 1 deletion pyflowline/mesh/mpas/create_mpas_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import importlib
import numpy as np
from osgeo import ogr, osr, gdal
import netCDF4 as nc
from pyflowline.formats.convert_attributes import convert_gcs_attributes_to_cell
gdal.UseExceptions()
iFlag_cython = importlib.util.find_spec("cython")
Expand Down Expand Up @@ -33,6 +32,7 @@ def create_mpas_mesh(iFlag_global_in,
Returns:
_type_: _description_
"""
import netCDF4 as nc

if iFlag_antarctic_in is None:
iFlag_antarctic=0
Expand Down

0 comments on commit d3468a7

Please sign in to comment.