Skip to content

Commit

Permalink
Expanded Yosemite pack; added tool for searching NGMDB
Browse files Browse the repository at this point in the history
  • Loading branch information
kueda committed Oct 11, 2023
1 parent 1843581 commit d9c2ca0
Show file tree
Hide file tree
Showing 11 changed files with 344 additions and 33 deletions.
83 changes: 83 additions & 0 deletions ngmdb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# https://ngmdb.usgs.gov/ngm-bin/ngm_search_json.pl?State=CA&Counties=Contra%20Costa&Counties=Alameda

import argparse
import re
import requests
from rich.console import Console
from rich.table import Table
from rich.highlighter import RegexHighlighter
from rich.theme import Theme

SEARCH_ENDPOINT = "https://ngmdb.usgs.gov/ngm-bin/ngm_search_json.pl"
STATE_CODES = [
"AK", "AL", "AR", "AS", "AZ", "CA", "CO", "CT", "DC", "DE", "FL", "GA", "GU",
"HI", "IA", "ID", "IL", "IN", "KS", "KY", "LA", "MA", "MD", "ME", "MI", "MN",
"MO", "MP", "MS", "MT", "NC", "ND", "NE", "NH", "NJ", "NM", "NV", "NY", "OH",
"OK", "OR", "PA", "PR", "RI", "SC", "SD", "TN", "TX", "UT", "VA", "VI", "VT",
"WA", "WI", "WV", "WY"
]

class GeologicMapHighlighter(RegexHighlighter):
"""Highlight text relative to geologic maps"""
base_style = "underfoot."
highlights = [
re.compile(r"(?P<geologic>geologic|geology)", re.IGNORECASE),
re.compile(r"(?P<geologic_map>geologic map)", re.IGNORECASE),
re.compile(r"(?P<database>database)", re.IGNORECASE)
]


theme = Theme({
"underfoot.geologic_map": "bold green",
"underfoot.geologic": "green",
"underfoot.database": "bold yellow"
})

if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Search NGMDB for geologic sources")
parser.add_argument(
"--state",
type=str,
choices=STATE_CODES,
help="US state (two-letter)"
)
parser.add_argument(
"--counties",
type=str,
action="append"
)
args = parser.parse_args()
print(f"args: {args}")
response = requests.get(SEARCH_ENDPOINT, {
"State": args.state,
"Counties": args.counties,
"format": "gis"
})
# headers = ["title", "scale", "year", "url"]
# data = [[
# result["title"],
# result["scale"],
# result["year"],
# f"https://ngmdb.usgs.gov/Prodesc/proddesc_{result['id']}.htm",

# ] ]
# table = PrettyTable()
# table.field_names = headers
# table.align["title"] = "l"
# table.align["url"] = "l"
# table.add_rows(data)
# print(table)
table = Table(title="NGMDB Results", highlight=True)
table.add_column("title")
table.add_column("scale", justify="right")
table.add_column("year", justify="right")
table.add_column("url")
for result in response.json()["ngmdb_catalog_search"]["results"]:
table.add_row(
result["title"],
result["scale"],
str(result["year"]),
f"https://ngmdb.usgs.gov/Prodesc/proddesc_{result['id']}.htm"
)
console = Console(highlighter=GeologicMapHighlighter(), theme=theme)
console.print(table)
33 changes: 6 additions & 27 deletions packs/us-ca-yosemite.geojson
Original file line number Diff line number Diff line change
@@ -1,29 +1,8 @@
{
"coordinates": [
[
[
[
-120,
37.4
],
[
-120,
38.3
],
[
-119,
38.3
],
[
-119,
37.4
],
[
-120,
37.4
]
]
]
],
"type": "MultiPolygon"
"type": "FeatureCollection",
"name": "us-ca-yosemite",
"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },
"features": [
{ "type": "Feature", "properties": { }, "geometry": { "type": "Polygon", "coordinates": [ [ [ -120.382118026905886, 37.983248080837676 ], [ -119.548444680299653, 38.68819417598732 ], [ -118.435167636308194, 37.901303110554608 ], [ -119.319612926281664, 37.106095341234457 ], [ -120.382118026905886, 37.983248080837676 ] ] ] } }
]
}
17 changes: 11 additions & 6 deletions packs/us-ca-yosemite.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"admin1": "United States",
"admin2": "California",
"bbox": {
"bottom": 37.4,
"left": -120,
"right": -119,
"top": 38.3
"bottom": 37.10609534123446,
"left": -120.38211802690589,
"right": -118.4351676363082,
"top": 38.68819417598732
},
"description": "Yosemite National Park and surrounding areas of the Sierra Nevada mountains",
"geojson": {
Expand All @@ -15,16 +15,21 @@
"name": "Yosemite National Park and surrounding area, CA, USA",
"osm": "http://download.geofabrik.de/north-america/us/california/norcal-latest.osm.pbf",
"rock": [
"sim3318",
"i1874",
"gam_25_walkerlake_1963_gis",
"of2005_1305_ca"
],
"water": [
"nhdplus_h_1605_hu4",
"nhdplus_h_1804_hu4",
"nhdplus_h_1809_hu4",
"nhdplus_h_1804_hu4",
"nhdplus_h_1606_hu4",
"nhdplus_h_1605_hu4",
"tiger_water_06003",
"tiger_water_06043",
"tiger_water_06109",
"tiger_water_06019",
"tiger_water_32005",
"tiger_water_06051",
"tiger_water_06039"
]
Expand Down
8 changes: 8 additions & 0 deletions sources/gam_25_walkerlake_1963_gis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"""
Geologic map of California : Walker Lake sheet
"""

from gam_25_walkerlake_1963_gis import run

if __name__ == "__main__":
run()
29 changes: 29 additions & 0 deletions sources/gam_25_walkerlake_1963_gis/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""
Geologic map of California : Walker Lake sheet
"""

import os
import re

from util.rocks import process_usgs_source
from util.proj import NAD83_CA_ALBERS


def run():
process_usgs_source(
base_path=os.path.realpath(__file__),
url="https://www.conservation.ca.gov/cgs/Documents/Publications/Geologic-Atlas-Maps/"
"GAM_25-WalkerLake-1963-GIS.zip",
extracted_file_path="GAM_25-WalkerLake-1963-GIS/GAM_25_WalkerLake-open/GM_MapUnitPolys.shp",
srs=NAD83_CA_ALBERS,
use_unzip=True,
polygons_join_col="MapUnit",
mappable_metadata_csv_path="GAM_25-WalkerLake-1963-GIS/GAM_25_WalkerLake-open/"
"DescriptionOfMapUnits.csv",
mappable_metadata_mapping={
"code": "MapUnit",
"title": "FullName",
"span": "Age",
"description": "Descr"
}
)
23 changes: 23 additions & 0 deletions sources/gam_25_walkerlake_1963_gis/citation.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[
{
"type": "map",
"edition": "1st",
"publisher": "California Department of Conservation",
"scale": "1:250000",
"title": "Geologic map of California : Walker Lake Sheet",
"URL": "https://www.conservation.ca.gov/cgs/rgm",
"author": [
{
"family": "Koenig",
"given": "James B."
}
],
"issued": {
"date-parts": [
[
"1963"
]
]
}
}
]
8 changes: 8 additions & 0 deletions sources/sim3318.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"""
Geologic Map of the Bodie Hills, California and Nevada
"""

from sim3318 import run

if __name__ == "__main__":
run()
18 changes: 18 additions & 0 deletions sources/sim3318/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import util
import os

from util.rocks import process_usgs_source


def run():
process_usgs_source(
base_path=os.path.realpath(__file__),
url="https://pubs.usgs.gov/sim/3318/downloads/SIM3318_Geodatabase_Shapefiles.zip",
extracted_file_path="SIM3318_Geodatabase_Shapefiles/SIM3318_shapefiles/Polygons.shp",
use_unzip=True,
srs=util.WGS84_UTM11_PROJ4,
metadata_csv_path=os.path.join(
os.path.dirname(os.path.realpath(__file__)),
"units.csv"
)
)
51 changes: 51 additions & 0 deletions sources/sim3318/citation.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
[
{
"id": "http://zotero.org/users/local/b90sdi4a/items/KE9JXDA7",
"type": "map",
"collection-title": "Scientific Investigations Map",
"language": "en",
"note": "collection-title: Scientific Investigations Map",
"publisher": "U.S. Geological Survey",
"scale": "1:50000",
"title": "Geologic Map of the Bodie Hills, California and Nevada",
"URL": "https://pubs.usgs.gov/sim/3318/",
"author": [
{
"family": "John",
"given": "David A."
},
{
"family": "Bray",
"given": "Edward A.",
"non-dropping-particle": "du"
},
{
"family": "Box",
"given": "Stephen E."
},
{
"family": "Vikre",
"given": "Peter G."
},
{
"family": "Rytuba",
"given": "James J."
},
{
"family": "Fleck",
"given": "Robert J."
},
{
"family": "Moring",
"given": "Barry C."
}
],
"issued": {
"date-parts": [
[
"2015"
]
]
}
}
]
Loading

0 comments on commit d9c2ca0

Please sign in to comment.