Skip to content

Commit

Permalink
update class.py to avoid json
Browse files Browse the repository at this point in the history
avoiding json in getting spatial data
  • Loading branch information
ericnost authored Sep 20, 2022
1 parent 35b59b8 commit 0ecfa5a
Showing 1 changed file with 2 additions and 47 deletions.
49 changes: 2 additions & 47 deletions class.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,54 +563,10 @@ def get_spatial_data(self):

def sqlizer(query):
'''
takes a default sql and injects a query into it
takes a default query and gets results
'''

# Currently (June 2022) not working
# Develop sql
"""
sql =
SELECT jsonb_build_object(
'type', 'FeatureCollection', 'features', jsonb_agg(features.feature)
)
FROM (
SELECT jsonb_build_object(
'type', 'Feature','id', gid, 'geometry',
ST_AsGeoJSON(geom)::jsonb,'properties',
to_jsonb(inputs) - 'gid' - 'geom'
) feature
FROM (
"""""" <- +query+ in here
) inputs
) features;
"""

# Develop sql
sql="""
SELECT jsonb_build_object(
'data', jsonb_agg(features.feature)
) FROM (
SELECT (
row_to_json(inputs)
) feature
FROM (
"""+query+"""
) inputs
) features
"""

#print(sql) # Debugging
url = 'http://portal.gss.stonybrook.edu/echoepa/index2.php?query='
data_location = url + urllib.parse.quote_plus(sql) + '&pg'
#print(data_location) # Debugging
#result = geopandas.read_file(data_location)

# Currently (June 2022) need to do extra conversion
response = requests.get(data_location)
results = response.json()
data = results["data"]
result = pd.read_json(json.dumps(data))
result = utilities.get_data(query)

result['geometry'] = geopandas.GeoSeries.from_wkb(result['wkb_geometry'])
result.drop("wkb_geometry", axis=1, inplace=True)
Expand Down Expand Up @@ -655,7 +611,6 @@ def sqlizer(query):

#print(units) # Debugging
# Matching with ECHO database (FAC_DERIVED_HUC - 8). Extras get cut with clip.
# THIS IS VERY SPECIFIC TO JUNE 2022 DB CONFIGURATION
if self.unit_type == "HUC8 Watersheds":
units = ["0" + str(unit) if len(str(unit)) != 8 else str(unit) for unit in units] # Accounting for cut leading 0s
if self.unit_type == "HUC10 Watersheds":
Expand Down

0 comments on commit 0ecfa5a

Please sign in to comment.