I have this working URL query for this
dataset
https://data.ny.gov/resource/9a8c-vfzj.geojson?$limit=100000&$$app_token=mytoken&$where=county in('Kings','Queens','Bronx','Richmond','New York')
Now I want to pull it and save it to a GeoJSON with ogr2ogr
ogr2ogr -f "GeoJSON" /home/thefile.geojson "https://data.ny.gov/resource/9a8c-vfzj.geojson?$limit=100000&$$app_token=mytoken&$where=county in('Kings','Queens','Bronx','Richmond','New York')" OGRGeoJSON -s_srs EPSG:4326 -progress
ERROR 1: HTTP error code : 400
FAILURE:
Unable to open datasource `https://data.ny.gov/resource/9a8c-vfzj.geojson?=100000&39457app_token=mytoken&=county in('Kings','Queens','Bronx','Richmond','New York')' with the following drivers.
the URL query works when I put it in the browser so I am wondering what the problem could be. I took out New York too see if it was the spaces in the URL being executed from the CMD but still no luck.
Best Answer
You will find a working sample code below to directly get the data from the URL and push it to a PostGIS table (I've considered you already have an existing database and ran
CREATE EXTENSION postgis;
PS: Tested on Linux, with Bash. Single quotes around remote url are important to avoid escaping
$
character with\$
.