Skip to content

Commit

Permalink
update names for various file fields
Browse files Browse the repository at this point in the history
  • Loading branch information
changliao1025 committed Aug 18, 2023
1 parent fa18496 commit ec59d72
Show file tree
Hide file tree
Showing 12 changed files with 130 additions and 65 deletions.
16 changes: 8 additions & 8 deletions pyflowline/algorithms/intersect/intersect_flowline_with_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ def intersect_flowline_with_mesh(iMesh_type_in, sFilename_mesh_in, sFilename_flo
pLayerOut = pDataset_out.CreateLayer('flowline', pSpatial_reference_flowline, ogr.wkbMultiLineString)
# Add one attribute
pLayerOut.CreateField(ogr.FieldDefn('lineid', ogr.OFTInteger64)) #long type for high resolution
pLayerOut.CreateField(ogr.FieldDefn('segment', ogr.OFTInteger)) #long type for high resolution
pLayerOut.CreateField(ogr.FieldDefn('order', ogr.OFTInteger)) #long type for high resolution
pLayerOut.CreateField(ogr.FieldDefn('stream_segment', ogr.OFTInteger)) #long type for high resolution
pLayerOut.CreateField(ogr.FieldDefn('stream_order', ogr.OFTInteger)) #long type for high resolution
pLayerDefn = pLayerOut.GetLayerDefn()
pFeatureOut = ogr.Feature(pLayerDefn)
lID_flowline = 0
Expand Down Expand Up @@ -84,8 +84,8 @@ def intersect_flowline_with_mesh(iMesh_type_in, sFilename_mesh_in, sFilename_flo
for j in range (nfeature_flowline):
pFeature_flowline = pLayer_flowline.GetFeature(j)
pGeometry_flowline = pFeature_flowline.GetGeometryRef()
iStream_segment = pFeature_flowline.GetField("segment")
iStream_order = pFeature_flowline.GetField("order")
iStream_segment = pFeature_flowline.GetField("stream_segment")
iStream_order = pFeature_flowline.GetField("stream_order")
if (pGeometry_flowline.IsValid()):
pass
else:
Expand All @@ -99,8 +99,8 @@ def intersect_flowline_with_mesh(iMesh_type_in, sFilename_mesh_in, sFilename_flo
if pGeometrytype_intersect == 'LINESTRING':
pFeatureOut.SetGeometry(pGeometry_intersect)
pFeatureOut.SetField("lineid", lID_flowline)
pFeatureOut.SetField("segment", iStream_segment)
pFeatureOut.SetField("order", iStream_order)
pFeatureOut.SetField("stream_segment", iStream_segment)
pFeatureOut.SetField("stream_order", iStream_order)
pLayerOut.CreateFeature(pFeatureOut)

aCoords = list()
Expand All @@ -125,8 +125,8 @@ def intersect_flowline_with_mesh(iMesh_type_in, sFilename_mesh_in, sFilename_flo
Line = pGeometry_intersect.GetGeometryRef(i)
pFeatureOut.SetGeometry(Line)
pFeatureOut.SetField("lineid", lID_flowline)
pFeatureOut.SetField("segment", iStream_segment)
pFeatureOut.SetField("order", iStream_order)
pFeatureOut.SetField("stream_segment", iStream_segment)
pFeatureOut.SetField("stream_order", iStream_order)
pLayerOut.CreateFeature(pFeatureOut)
aCoords = list()
for i in range(0, Line.GetPointCount()):
Expand Down
2 changes: 1 addition & 1 deletion pyflowline/classes/_visual.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def _plot_mesh_with_flowline(self,
sFilename_json = os.path.join(pBasin.sWorkspace_output_basin, dummy)
aFilename_in.append(sFilename_json)
aFlag_color.append(1)
aVariable_in.append('segment')
aVariable_in.append('stream_segment')

map_multiple_vector_data(aFiletype_in,
aFilename_in,
Expand Down
2 changes: 1 addition & 1 deletion pyflowline/classes/_visual_basin.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def basin_plot(self,
sFilename_output_in=sFilename_output_in,
#sTitle_in= 'Flow direction with observation',
aFlag_thickness_in= [1, 0, 0],
aVariable_in= ['drainage_area', '', 'segment'],
aVariable_in= ['drainage_area', '', 'stream_segment'],
aLegend_in = aLegend_in,
aFlag_color_in = [0, 0, 1],
aFlag_fill_in = [0, 0, 0])
Expand Down
6 changes: 3 additions & 3 deletions pyflowline/classes/basin.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ def flowline_simplification(self):
export_flowline_to_geojson(aFlowline_basin_simplified,
sFilename_out,
aAttribute_data=[aStream_segment],
aAttribute_field=['iStream_segment'],
aAttribute_field=['stream_segment'],
aAttribute_dtype=['int'])

#build stream order
Expand All @@ -572,7 +572,7 @@ def flowline_simplification(self):
export_flowline_to_geojson(aFlowline_basin_simplified,
sFilename_out,
aAttribute_data=[aStream_segment, aStream_order],
aAttribute_field=['iStream_segment','iStream_order'],
aAttribute_field=['stream_segment','stream_order'],
aAttribute_dtype=['int','int'])

if self.iFlag_break_by_distance==1:
Expand Down Expand Up @@ -694,7 +694,7 @@ def reconstruct_topological_relationship(self, iMesh_type, sFilename_mesh):
export_flowline_to_geojson( aFlowline_basin_conceptual,
sFilename_out,
aAttribute_data=[aStream_segment, aStream_order],
aAttribute_field=['iStream_segment','iStream_order'],
aAttribute_field=['stream_segment','stream_order'],
aAttribute_dtype=['int','int'])

self.aFlowline_basin_conceptual = aFlowline_basin_conceptual
Expand Down
21 changes: 18 additions & 3 deletions pyflowline/classes/pycase.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ class flowlinecase(object):
iFlag_intersect = 1
iFlag_rotation=0
iFlag_break_by_distance = 0 #if the distance between two vertice are far,
iResolution_index = 10
iFlag_dggrid = 0
nOutlet = 1 #by default , there shoule ne only one ouelet
dResolution_degree=0.0
Expand All @@ -121,6 +122,7 @@ class flowlinecase(object):
sRegion=''
sModel=''
sMesh_type ='hexagon'
sDggrid_type = 'ISEA3H'

sCase=''
sDate=''
Expand Down Expand Up @@ -240,6 +242,16 @@ def __init__(self, aConfig_in,
else:
self.iFlag_dggrid=0

if 'iResolution_index' in aConfig_in:
self.iResolution_index = int(aConfig_in['iResolution_index'])
else:
self.iResolution_index=10

if 'sDggrid_type' in aConfig_in:
self.sDggrid_type = aConfig_in['sDggrid_type']
else:
self.sDggrid_type='ISEA3H'

if 'nOutlet' in aConfig_in:
self.nOutlet = int(aConfig_in['nOutlet'])

Expand Down Expand Up @@ -770,10 +782,11 @@ def mesh_generation(self, iFlag_antarctic_in=None):

aDggrid = create_dggrid_mesh(iFlag_global,
iFlag_save_mesh,
dResolution_meter,
sFilename_mesh,
sWorkspace_output,
iResolution_index_in= self.iResolution_index,
iFlag_antarctic_in=iFlag_antarctic_in,
sDggrid_type_in = self.sDggrid_type,
sFilename_boundary_in = self.sFilename_mesh_boundary)

pass
Expand All @@ -782,7 +795,9 @@ def mesh_generation(self, iFlag_antarctic_in=None):
iFlag_save_mesh,
dResolution_meter,
sFilename_mesh,
sWorkspace_output)
sWorkspace_output,
iResolution_index_in= self.iResolution_index,
sDggrid_type_in = self.sDggrid_type)
pass


Expand All @@ -807,7 +822,7 @@ def mesh_generation(self, iFlag_antarctic_in=None):
print('Unsupported mesh type?')
return
else:
#read mesh?
#read mesh? this function is not completed
iMesh_type = self.iMesh_type
aCell_out = read_mesh_json_w_topology(iMesh_type, self.sFilename_mesh)
pass
Expand Down
38 changes: 20 additions & 18 deletions pyflowline/external/pyearth/gis/kml/convert_geojson_to_kml.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,37 @@
def convert_geojson_to_kml(sFilename_geojson, sFilename_kml):
# Read the GeoJSON file

geojson_driver = ogr.GetDriverByName('GeoJSON')
geojson_data_source = geojson_driver.Open(sFilename_geojson)
layer = geojson_data_source.GetLayer()
#geojson_driver = ogr.GetDriverByName('GeoJSON')
#geojson_data_source = geojson_driver.Open(sFilename_geojson)
#layer = geojson_data_source.GetLayer()

# Create a KML object
kml = simplekml.Kml()
#kml = simplekml.Kml()

# Iterate over features in the GeoJSON layer
feature = layer.GetNextFeature()
while feature:
#feature = layer.GetNextFeature()
#while feature:
# Get the geometry of the feature
geometry = feature.GetGeometryRef()
sGeometry_type = geometry.GetGeometryName()
## geometry = feature.GetGeometryRef()
# sGeometry_type = geometry.GetGeometryName()
# Convert the geometry to WKT
wkt = geometry.ExportToWkt()
if(sGeometry_type == 'POLYGON'):
# wkt = geometry.ExportToWkt()
# if(sGeometry_type == 'POLYGON'):
# Create a KML placemark and add it to the KML object
polygon = kml.newpolygon()
polygon.geometry = simplekml.Geometry(wkt=wkt)
else:
if (sGeometry_type == 'LINESTRING'):
#polygon = kml.newpolygon()
#polygon.geometry = simplekml.Geometry(wkt=wkt)
# pass
# else:
# if (sGeometry_type == 'LINESTRING'):
# Create a KML placemark and add it to the KML object
linestring = kml.newlinestring()
linestring.geometry = simplekml.Geometry(wkt=wkt)
#linestring = kml.newlinestring()
#linestring.geometry = simplekml.Geometry(wkt=wkt)
# pass

# Move to the next feature
feature = layer.GetNextFeature()
#feature = layer.GetNextFeature()

# Save the KML to a file
#sFilename_kml = 'output.kml'
kml.save(sFilename_kml)
#kml.save(sFilename_kml)
return
4 changes: 3 additions & 1 deletion pyflowline/formats/convert_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
from pyflowline.classes.mpas import pympas
from pyflowline.classes.tin import pytin

def convert_gcs_attributes_to_cell(iMesh_type_in, dLongitude_center_in, dLatitude_center_in,
def convert_gcs_attributes_to_cell(iMesh_type_in,
dLongitude_center_in,
dLatitude_center_in,
aCoordinates_gcs_in,
aVertexID_in,
aEdgeID_in,
Expand Down
4 changes: 2 additions & 2 deletions pyflowline/formats/export_flowline.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def export_flowline_to_geojson( aFlowline_in,

pLayer_json = pDataset_json.CreateLayer('flowline', pSpatial_reference_in, ogr.wkbLineString)
# Add one attribute
pLayer_json.CreateField(ogr.FieldDefn('flowlineid', ogr.OFTInteger64)) #long type for high resolution
pLayer_json.CreateField(ogr.FieldDefn('lineid', ogr.OFTInteger64)) #long type for high resolution

#add the other fields
if iFlag_attribute ==1:
Expand Down Expand Up @@ -94,7 +94,7 @@ def export_flowline_to_geojson( aFlowline_in,
pGeometry_out = ogr.CreateGeometryFromWkb(dummy1.wkb)
pFeature_out.SetGeometry(pGeometry_out)

pFeature_out.SetField("flowlineid", lID)
pFeature_out.SetField("lineid", lID)
if iFlag_attribute == 1:
for k in range(nAttribute1):
sField = aAttribute_field[k]
Expand Down
8 changes: 4 additions & 4 deletions pyflowline/formats/export_vertex.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ def export_vertex_to_geojson(aVertex_in,
pDataset_json = pDriver.CreateDataSource(sFilename_json_in)
pLayer_json = pDataset_json.CreateLayer('vertex', pSpatial_reference_in, ogr.wkbPoint)
# Add one attribute
pLayer_json.CreateField(ogr.FieldDefn('id', ogr.OFTInteger64)) #long type for high resolution
pLayer_json.CreateField(ogr.FieldDefn('pointid', ogr.OFTInteger64)) #long type for high resolution
if iFlag_attribute ==1:
pLayer_json.CreateField(ogr.FieldDefn('con', ogr.OFTInteger64)) #long type for high resolution
pLayer_json.CreateField(ogr.FieldDefn('connectivity', ogr.OFTInteger64)) #long type for high resolution
pass

pLayerDefn = pLayer_json.GetLayerDefn()
Expand All @@ -65,9 +65,9 @@ def export_vertex_to_geojson(aVertex_in,

pGeometry_out = ogr.CreateGeometryFromWkb(dummy1.wkb)
pFeature_out.SetGeometry(pGeometry_out)
pFeature_out.SetField("id", lID)
pFeature_out.SetField("pointid", lID)
if iFlag_attribute ==1:
pFeature_out.SetField("con", int(aAttribute[i]) )
pFeature_out.SetField("connectivity", int(aAttribute[i]) )

pLayer_json.CreateFeature(pFeature_out)
lID = lID + 1
Expand Down
4 changes: 2 additions & 2 deletions pyflowline/formats/read_flowline.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def read_flowline_geojson(sFilename_geojson_in):
for n in range(ldefn.GetFieldCount()):
fdefn = ldefn.GetFieldDefn(n)
schema.append(fdefn.name)
if 'segment' in schema:
if 'stream_segment' in schema:
iFlag_segment = 1
else:
iFlag_segment = 0
Expand All @@ -189,7 +189,7 @@ def read_flowline_geojson(sFilename_geojson_in):
pGeometry_in = pFeature_geojson.GetGeometryRef()
sGeometry_type = pGeometry_in.GetGeometryName()
if iFlag_segment ==1:
iStream_segment = pFeature_geojson.GetField("segment")
iStream_segment = pFeature_geojson.GetField("stream_segment")
else:
iStream_segment = -1

Expand Down
4 changes: 2 additions & 2 deletions pyflowline/formats/read_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def read_mesh_json(iMesh_type_in, sFilename_mesh_in):
for n in range(ldefn.GetFieldCount()):
fdefn = ldefn.GetFieldDefn(n)
schema.append(fdefn.name)
if 'segment' in schema:
if 'stream_segment' in schema:
iFlag_segment = 1
else:
iFlag_segment = 0
Expand Down Expand Up @@ -85,7 +85,7 @@ def read_mesh_json_w_topology(iMesh_type_in, sFilename_mesh_in):
for n in range(ldefn.GetFieldCount()):
fdefn = ldefn.GetFieldDefn(n)
schema.append(fdefn.name)
if 'segment' in schema:
if 'stream_segment' in schema:
iFlag_segment = 1
else:
iFlag_segment = 0
Expand Down
Loading

0 comments on commit ec59d72

Please sign in to comment.