Skip to content

Commit

Permalink
issue #17 and issue #18
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianKriger authored Jul 2, 2022
1 parent f296b7f commit ebc0d36
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 47 deletions.
92 changes: 52 additions & 40 deletions village_campus/mwe/osm3DCode2.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,8 @@ def requestOsmParking(jparams):

def prepareRoads(jparams, rd, pk, aoi, aoibuffer, gt_forward, rb):
"""
process ---buffer with out overlap--- the osm roads
process street network ---buffer with no overlap, trim back from tunnel, parking_entrance
and under bridge --- return .geojson
"""
from shapely.wkt import loads
import itertools
Expand All @@ -259,6 +260,9 @@ def ownbuffer(row):

def ownbuffer02(row):
return row.geometry.buffer(round(float(row['width']) / 2, 2), cap_style=2)

def ownbuffer03(row):
return row.geometry.buffer(round(float(row['width']) + 0.25 / 2, 2), cap_style=2)

#rd = gpd.read_file(jparams['gjson_proj-rd'])
rd = rd.copy()
Expand Down Expand Up @@ -361,7 +365,7 @@ def ownbuffer02(row):
rd_b = rd_b.explode()

#-- buffer the tunnel features and cut from the roads
t_buffer = tunnel.buffer(1, cap_style=2)
t_buffer = tunnel.buffer(0.5, cap_style=2)
t_buffer = gpd.GeoDataFrame(crs=jparams['crs'], geometry=t_buffer)
rd_b = gpd.overlay(rd_b, t_buffer, how='difference')
rd_b = rd_b.explode()
Expand All @@ -380,6 +384,15 @@ def ownbuffer02(row):
pk_buffer = gpd.GeoDataFrame(crs=jparams['crs'], geometry=pk_buffer)
rd_b = gpd.overlay(rd_b, pk_buffer, how='difference')

#-- remove bridges and trim back roads under bridges
bridge_b = bridge.copy()
bridge_b02 = bridge.copy()
bridge_b['geometry'] = bridge_b.apply(ownbuffer02, axis=1)
bridge_b02['geometry'] = bridge_b02.apply(ownbuffer03, axis=1)
bridge_b02 = bridge_b02.dissolve()
rd_b = gpd.overlay(rd_b, bridge_b02, how='difference')
rd_b = rd_b.explode()

#-- trim the roads to the aoi
rd_b = gpd.clip(rd_b, aoi)
one = gpd.clip(join, rd_b)
Expand All @@ -394,28 +407,7 @@ def ownbuffer02(row):
as_index=False, dropna=False)
one = one.explode()
one.reset_index(drop=True, inplace=True)

# #-- process bridge ---we want the most basic case; a bridge with two nodes either side of a span
# bridge['vertex_counter'] = 0

# for index, row in bridge.iterrows():
# if row.bridge == 'yes':
# bridge.at[index,'vertex_counter'] = len(row['geometry'].coords)

# bridge = bridge[bridge['vertex_counter'] == 2]
# bridge_b = bridge.copy()
# bridge_b['geometry'] = bridge_b.apply(ownbuffer02, axis=1)
# #-- cut the one bridge from the street network
# for i, row in bridge_b.iterrows():
# hw = row.highway
# su = row.surface
# second = one.loc[(one['highway'] == hw) & (one['surface'] == su)]
# #idx = one.loc[(one['highway'] == hw) & (one['surface'] == su)].index.to_list()
# first = gpd.GeoDataFrame(crs=jparams['crs'], geometry=[row.geometry])
# second02 = gpd.GeoDataFrame(crs=jparams['crs'], geometry=second.geometry)
# result = gpd.overlay(second02, first, how='difference')
# one.iloc[second.index, one.columns.get_loc('geometry')] = result


#-- account for null/None values
one.dropna(subset=['geometry'], inplace=True)
one.loc[one["id"].isnull(), "id"] = (one["id"].isnull().cumsum()).astype(float) #"Other" +
Expand Down Expand Up @@ -516,9 +508,9 @@ def assignZ(ts, gt_forward, rb): # rfname,

def writegjson(ts, jparams):#, fname):
"""
read the gdal geojson and create new attributes in osm vector
read the building gpd and create new attributes in osm vector
~ ground height, relative building height and roof height.
write the result to file.
write the result to .geojson
"""
#-- take care of non-Polygon LineString's
for i, row in ts.iterrows():
Expand Down Expand Up @@ -619,18 +611,32 @@ def writegjson(ts, jparams):#, fname):

def prep_Brdgjson(bridge, jparams):#, fname):
"""
read the gdal skywalk geojson and create new attributes in osm vector
~ ground height, relative building min_height and roof/max height.
write the result to file.
read the bridge gpd and prepare the .geojson
"""
def ownbuffer02(row):
return row.geometry.buffer(round(float(row['width']) / 2, 2), cap_style=2)

#-- at a most basic level we only create bridge CityObjects of straight line features
#-- with two vertices either side of a span

bridge = bridge[bridge['bridge_structure'] != 'humpback']
bridge['vertex_counter'] = 0

for index, row in bridge.iterrows():
if row.bridge == 'yes':
bridge.at[index,'vertex_counter'] = len(row['geometry'].coords)

bridge = bridge[bridge['vertex_counter'] == 2]
bridge_b = bridge.copy()
bridge_b['geometry'] = bridge_b.apply(ownbuffer02, axis=1)

#-- iterate through the list of buildings and create GeoJSON features rich in attributes
_bridge = {
"type": "FeatureCollection",
"features": []
}

for i, row in bridge.iterrows():
for i, row in bridge_b.iterrows():
f = {
"type" : "Feature"
}
Expand All @@ -655,14 +661,15 @@ def prep_Brdgjson(bridge, jparams):#, fname):
_bridge['features'].append(f)

#-- store the data as GeoJSON
with open(jparams['brdge_gjson_out'], 'w') as outfile:
json.dump(_bridge, outfile)
#with open(jparams['brdge_gjson_out'], 'w') as outfile:
#json.dump(_bridge, outfile)

return _bridge

def prep_Skygjson(skywalk, jparams):#, fname):
"""
read the gdal skywalk geojson and create new attributes in osm vector
read the skywalk gpd and prepare and return the .geojson - create new attributes in osm vector
~ ground height, relative building min_height and roof/max height.
write the result to file.
"""
# take care of non-Polygon LineString's
for i, row in skywalk.iterrows():
Expand Down Expand Up @@ -718,6 +725,10 @@ def prep_Skygjson(skywalk, jparams):#, fname):
return skyprints

def prep_roof(roof, jparams):#, fname):
"""
read the roof gpd; prepare and return the .geojson - create new attributes in osm vector
~ *roof_height.
"""
storeyheight = 2.8
#-- iterate and create GeoJSON features
_roof = {
Expand Down Expand Up @@ -858,7 +869,7 @@ def getBldVertices(dis):
all_coords = []
dps = 2
segs = {}
geoms = {}
#geoms = {}

for ids, row in dis.iterrows():
oring, z = list(row.geometry.exterior.coords), row['ground_height']
Expand Down Expand Up @@ -1261,11 +1272,12 @@ def output_cityjsonR(extent, minz, maxz, T, pts, t_list, rd_pts, jparams, bridge
#lsgeom.append(shape(each['geometry'])) #-- geom are casted to Fiona's
rdattributes.append(each['properties'])

if jparams['bridge'] == 'Yes':
brg = fiona.open(jparams['brdge_gjson_out'])
if jparams['bridge'] == 'Yes' and len(bridge) > 1:
#brg = fiona.open(jparams['brdge_gjson_out'])
brggeom = [] #-- list of the geometries
brggeomattributes = [] #-- list of the attributes
for each in brg:
#for each in brg:
for (s, each) in enumerate(bridge['features']):
brggeom.append(shape(each['geometry'])) #-- geom are casted to Fiona's
brggeomattributes.append(each['properties'])
else:
Expand Down Expand Up @@ -1724,15 +1736,15 @@ def doVcBndGeomRd(lsgeom, lsattributes, rdattributes, t_list, rd_pts, extent, mi
}
}
},
{"featureIDs": ["Building"],
{"featureIDs": ["Building", "Road"],
"source": [
{
"description": "OpenStreetMap contributors",
"sourceReferenceSystem": "urn:ogc:def:crs:EPSG:4326",
"sourceCitation": "https://www.openstreetmap.org",
}],
"processStep": {
"description" : "Processing of building vector contributions using osm_LoD1_3DCityModel workflow",
"description" : "Processing of vector contributions using osm_LoD1_3DCityModel workflow",
"processor": {
"contactName": jparams['cjsn_contactName'],
"contactType": jparams['cjsn_contactType'],
Expand Down
8 changes: 4 additions & 4 deletions village_campus/mwe/osm3DMain2.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def main():
start = time.time()

try:
jparams = json.load(open('osm3Dcput_param.json'))
jparams = json.load(open('osm3DuEstate_param.json'))
except:
print("ERROR: something is wrong with the param.json file.")
sys.exit()
Expand Down Expand Up @@ -70,8 +70,8 @@ def main():
pk = requestOsmParking(jparams)
#projVec(jparams['gjson_proj-pk'], jparams['gjson-pk'], jparams['crs'])
one, bridge, hsr = prepareRoads(jparams, rd, pk, aoi, aoibuffer, gt_forward, rb)
if jparams['bridge'] == 'Yes':
prep_Brdgjson(bridge, jparams)
if jparams['bridge'] == 'Yes' and len(bridge) > 0:
bridge_b = prep_Brdgjson(bridge, jparams)

ts, skywalk, roof = assignZ(ts, gt_forward, rb) #jparams['projClip_raster'],
writegjson(ts, jparams)#['gjson-z_out'])
Expand Down Expand Up @@ -125,7 +125,7 @@ def main():
#writeObj(pts, t, 'wvft_cput3d.obj') ~ this will write the terrain surface only
if jparams['roads'] == "Yes":
output_cityjsonR(extent, minz, maxz, t, pts, t_list, rd_pts, jparams,
bridge, skywalk, roof, acoi, gt_forward, rb)
bridge_b, skywalk, roof, acoi, gt_forward, rb)
else:
output_cityjson(extent, minz, maxz, t, pts, jparams, skywalk, roof)

Expand Down
1 change: 0 additions & 1 deletion village_campus/mwe/osm3Dcput_param.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"roads": "Yes",
"osm_roads": "./data/rds-cput_out.geojson",
"bridge": "No",
"brdge_gjson_out": "./data/brdg-cput_out.geojson",

"in_raster": "./raster/LO19_050M_3318DC.tif",
"nodata": 3.402823466385289e+38,
Expand Down
3 changes: 1 addition & 2 deletions village_campus/mwe/osm3DuEstate_param.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@

"roads": "Yes",
"osm_roads": "./data/rds-ue_out.geojson",
"bridge": "No",
"brdge_gjson_out": "./data/brdg-ue_out.geojson",
"bridge": "Yes",

"in_raster": "./raster/LO19_050M_3318CD.tif",
"nodata": 3.402823466385289e+38,
Expand Down

0 comments on commit ebc0d36

Please sign in to comment.