Skip to content

Commit a98c148

Browse files
committed
Add support for polygons and switch to WKT representation
1 parent 6d8d7ab commit a98c148

File tree

2 files changed

+19
-34
lines changed

2 files changed

+19
-34
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ python edit.py example.json -ids 352 -fnames logo.gif
2727
Successfully modified record https://cd-sandbox.tind.io/records/352
2828
```
2929

30-
Get geo points from CaltechDATA. You can import this to a GIS program like QGIS
31-
using a delimited text import and projection epsg:4326
30+
Get geographic metadata from CaltechDATA with WKT representations in a csv file.
31+
You can import this to a GIS program like QGIS
32+
using a delimited text import and projection epsg:4326. You'll have to do one
33+
import for Geometry type Point and another for Geometry type Polygon.
3234

3335
```
3436
python get_geo.py caltechdata_geo.csv

get_geo.py

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -31,44 +31,27 @@
3131

3232
outfile = open(args.output,'w')
3333
writer = csv.writer(outfile)
34-
writer.writerow(['lat','lon','name','doi'])
34+
writer.writerow(['wkt','name','year','doi'])
3535

3636
for h in hits['hits']['hits']:
3737
metadata = decustomize_schema(h['metadata'])
3838
if 'geoLocations' in metadata:
39+
doi = 'https://doi.org/'+metadata['identifier']['identifier']
40+
title=metadata['titles'][0]['title'].split(':')[0]
3941
geo = metadata['geoLocations']
42+
year = metadata['publicationYear']
4043
for g in geo:
41-
#if 'geoLocationBox' in g:
42-
# box = g['geoLocationBox']
43-
# lat=[box['northBoundLatitude'],box['northBoundLatitude'],box['southBoundLatitude'],box['southBoundLatitude']]
44-
# lon=[box['eastBoundLongitude'],box['westBoundLongitude'],box['eastBoundLongitude'],box['westBoundLongitude']]
45-
# tlon,tlat = transform(from_proj,to_proj,lon,lat)
46-
# pt_lat=pt_lat+tlat
47-
# pt_lon= pt_lon+tlon
48-
# cen = metadata['publicationYear'][1]
49-
# dec = metadata['publicationYear'][2]
50-
# identifier.append(metadata['identifier']['identifier'])
51-
# author.append(metadata['creators'][0]['creatorName'])
52-
# title.append(metadata['titles'][0]['title'].split(':')[0])
53-
# year.append(metadata['publicationYear'])
54-
# color.append(clo)
55-
# x0 = x0 + [tlon[0],tlon[2],tlon[0],tlon[1]]
56-
# x1 = x1 + [tlon[1],tlon[3],tlon[2],tlon[3]]
57-
# y0 = y0 + [tlat[0],tlat[2],tlat[0],tlat[1]]
58-
# y1 = y1 + [tlat[1],tlat[3],tlat[2],tlat[3]]
44+
if 'geoLocationBox' in g:
45+
box = g['geoLocationBox']
46+
p1 = f"{box['eastBoundLongitude']} {box['northBoundLatitude']}"
47+
p2 = f"{box['westBoundLongitude']} {box['northBoundLatitude']}"
48+
p3 = f"{box['westBoundLongitude']} {box['southBoundLatitude']}"
49+
p4 = f"{box['eastBoundLongitude']} {box['southBoundLatitude']}"
50+
wkt = f'POLYGON (({p1}, {p2}, {p3}, {p4}, {p1}))'
51+
writer.writerow([wkt,title,year,doi])
52+
5953
if 'geoLocationPoint' in g:
6054
point = g['geoLocationPoint']
61-
#tlon,tlat =\
62-
#transform(from_proj,to_proj,point['pointLongitude'],point['pointLatitude'])
63-
#pt_lat=pt_lat+[tlat]
64-
#pt_lon= pt_lon+[tlon]
65-
doi = 'https://doi.org/'+metadata['identifier']['identifier']
66-
#author=author+[metadata['creators'][0]['creatorName']]
67-
title=metadata['titles'][0]['title'].split(':')[0]
68-
lat = point['pointLatitude']
69-
lon = point['pointLongitude']
70-
writer.writerow([lat,lon,title,doi])
71-
#year = year+[metadata['publicationYear']]
72-
#cen = metadata['publicationYear'][1]
73-
#dec = metadata['publicationYear'][2]
55+
wkt = f"POINT ({point['pointLongitude']} {point['pointLatitude']})"
56+
writer.writerow([wkt,title,year,doi])
7457

0 commit comments

Comments
 (0)