Skip to content

Commit 04121e1

Browse files
committed
initial commit
1 parent 96ce36c commit 04121e1

File tree

4 files changed

+73
-0
lines changed

4 files changed

+73
-0
lines changed

NSI/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
## Data Preparation
2+
3+
### Download NSI
4+
- curl
5+
6+
### Data Converstion to BUilindg Inventory
7+
8+
### Publish to PostgreSQL database

NSI/nsitobuildinginventory.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import fiona
2+
import uuid
3+
import copy
4+
import geopandas as gpd
5+
6+
# download NSI dataset
7+
8+
# read NSI geopackage
9+
# TODO this is a method of using geopandas.
10+
# However, even though this method has more advantage,
11+
# the saving to geopackage output has a crs error due to the fiona problem
12+
13+
def read_nsi_data(infile, outfile):
14+
gpkgname = ""
15+
gpkgpd = None
16+
for layername in fiona.listlayers(infile):
17+
gpkgpd = gpd.read_file(infile, layer=layername, crs='EPSG:4326')
18+
gpkgname = layername
19+
gpkgpd.to_file(outfile, layer=layername, driver="GPKG")
20+
21+
# def read_nsi_data(infile, outfile):
22+
# infile = fiona.open(infile)
23+
#
24+
# # add GUID field
25+
# infile = add_guid(infile, outfile)
26+
# print(infile)
27+
#
28+
# # add GUID field
29+
# def add_guid(infile, outfile):
30+
# # create list of each shapefile entry
31+
# shape_property_list = []
32+
# schema = infile.schema.copy()
33+
# schema['properties']['uuid'] = 'str:30'
34+
# for in_feature in infile:
35+
# # build shape feature
36+
# tmp_feature = copy.deepcopy(in_feature)
37+
# tmp_feature['properties']['guid'] = str(uuid.uuid4())
38+
# shape_property_list.append(tmp_feature)
39+
#
40+
# with fiona.open(outfile, 'w', 'GPKG', schema) as output:
41+
# print('create output geopackage........')
42+
# for i in range(len(shape_property_list)):
43+
# new_feature = shape_property_list[i]
44+
# output.write(new_feature)
45+
46+
# convert the values
47+
48+
# renamd the fields
49+
50+
# add missing fields
51+
52+
# save as geopackage
53+
54+
if __name__ == '__main__':
55+
# from osgeo import osr
56+
# sp = osr.SpatialReference()
57+
# target_crs = 'PROJCS["Geographic",GEOGCRS["WGS 84",ENSEMBLE["World Geodetic System 1984 ensemble",MEMBER["World Geodetic System 1984 (Transit)"],MEMBER["World Geodetic System 1984 (G730)"],MEMBER["World Geodetic System 1984 (G873)"],MEMBER["World Geodetic System 1984 (G1150)"],MEMBER["World Geodetic System 1984 (G1674)"],MEMBER["World Geodetic System 1984 (G1762)"],ELLIPSOID["WGS 84",6378137,298.257223563,LENGTHUNIT["metre",1]],ENSEMBLEACCURACY[2.0]],PRIMEM["Greenwich",0,ANGLEUNIT["degree",0.0174532925199433]],CS[ellipsoidal,2],AXIS["geodetic latitude (Lat)",north,ORDER[1],ANGLEUNIT["degree",0.0174532925199433]],AXIS["geodetic longitude (Lon)",east,ORDER[2],ANGLEUNIT["degree",0.0174532925199433]],USAGE[SCOPE["Horizontal component of 3D system."],AREA["World."],BBOX[-90,-180,90,180]],ID["EPSG",4326]]]'
58+
# sp.ImportFromWkt(target_crs)
59+
# sp.ExportToWkt()
60+
infile = "C:\\Users\\ywkim\\Documents\\NIST\\NSI\\joplin.gpkg"
61+
outfile = "C:\\Users\\ywkim\\Documents\\NIST\\NSI\\test.gpkg"
62+
read_nsi_data(infile, outfile)

NSI/posttodatabase.py

Whitespace-only changes.

NSI/requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
gdal>=3.4.2
2+
rasterio>=1.2.10
3+
fiona>=1.8.21

0 commit comments

Comments
 (0)