Reversed Latitude/Longitude US Tiger/Line Shape File to MySQL w/ OGR2OGRP - mysql

I've downloaded the latest set (2010) of TIGER edge shape files (ESRI shapefile format) from the US Census website and am loading them into MySQL using the GDAL ogr2ogr utility. A new table (geotest) does get created with a SHAPE column that has the geometry defined as a LINESTRING. However, I am seeing reversed latitude and longitude values that get reversed when running the following command:
ogr2ogr -f "MySQL" MySQL:"geo,user=myuser,host=localhost,password=mypwd" -nln geotest -nlt LINESTRING -append -a_srs "EPSG:4326" -lco engine=MYISAM tl_2010_01021_edges.shp
Mapping the latitude/longitude (after reversing them of course) they appear to be spot on so I suspect there is just something I am doing wrong or flag I am missing which is causing the latitude and longitudes to be transposed.
When I select the SHAPE column using astext() I get the following result:
LINESTRING(-86.69863 32.973164,-86.69853 32.97302,-86.69856 32.97287,-86.698613 32.972825,-86.6988 32.972825,-86.6989 32.972892,-86.6989 32.973002,-86.69874 32.97316,-86.69864 32.97318,-86.69863 32.973164)
Any ideas what I am doing wrong?

Related

Convert JSON to shapefile

I have a json file that contains a lot of data with polygons, lines, points. But I can't exploit it to export the data in shapefile. Can someone help me on how to get there. The data is here.
https://www.sia.aviation-civile.gouv.fr/produits-numeriques-en-libre-disposition/donnees-zones-geographiques-uas.html
if someone can help me solve this problem.
You can't export all of it to one shapefile as it is not possible to mix geometry types in a shapefile, so you will need 3 shapefiles (points, lines, polygons).
I would make use of ogr2ogr the Swiss army knife of vector formats and use something like:
ogr2ogr -nlt POINT -skipfailures points.shp geojsonfile.json
ogr2ogr -nlt LINESTRING -skipfailures linestrings.shp geojsonfile.json
ogr2ogr -nlt POLYGON -skipfailures polygons.shp geojsonfile.json

How do I convert one CRS (Coordinate Reference System) value into another using OSGeo4W Shell?

I have QGIS 2.18 (latest version) installed for windows (new users). Along came OSGeo4W Shell. Now using this shell, I want to convert a specific value in one CRS into another. For example, if I know coordinates in WGS84 (say, 91.7362, 26.1445 just to give an example), I would like to know how to convert it to Indian 1954/UTM Zone 46N (which are in meters) using OSGeoShell.
PS: I know there is a way because I once successfully found the way. I had copied the syntax of the command but I deleted the file by mistake and I can't find the way in net again even after long time searches. It was barely a 2 line and simple command.
I think, the command is:
osgeo4w
gdaltransform -s_srs EPSG:4326 -t_srs EPSG:XXXX < input.csv > output.txt
Where the EPSG codes are the codes for the CRS (4326 is for WGS84). You have to find out the epsg code for your target crs and then you can perform the transformation.

Can't simplify topojson for d3 mapping

I'm trying to map some statistical data of Italy and I need the infrastructure (railway and motorway) on top of it.
The problem is that I'm not able to simplify the infrastructure json file.
I'm using the openstreetmap shape of Italy by geofabbriK: http://download.geofabrik.de/europe/italy.html#
I've converted the roads.shp to json selecting only motorway and and primary roads using this command:
ogr2ogr -f GeoJSON -where "type IN ('motorway', 'motorway_link', 'primary', 'primary_link')" -t_srs EPSG:4326 roads.json roads.shp
I get a 55Mb json file. You can download it here: http://www.danielepennati.com/prove/mapping/roads_mw_pr.zip
Than I tryed to simplify and convert it in topojson.
Whit no -s command the new json file is about 13Mb
If I use -s or --simplify-proportion with any value form 1 to 0 I always get a max semplification of 95% and a filesize of 11Mb
How can I get a more simplified topojson?
Thanks
daniele

Creating Shape Files from SQL Server using Ogr2ogr

I am trying to run the following code in a command window. The code executes, but it gives me no values in the .SHP files. The table has GeographyCollections and Polygons stored in a Field of type Geography. I have tried many variations for the Geography type in the sql statement - Binary, Text etc. but no luck. The output .DBF file has data, so the connection to the database works, but the shape .Shp file and .shx file has no data and is of size 17K and 11 K, respectively.
Any suggestions?
ogr2ogr -f "ESRI Shapefile" -overwrite c:\temp -nln Zip_States -sql "SELECT [ID2],[STATEFP10],[ZCTA5CE10],GEOMETRY::STGeomFromWKB([Geography].STAsBinary(),4326).STAsText() AS [Geography] FROM [GeoSpatial].[dbo].[us_State_Illinois_2010]" ODBC:dbo/GeoSpatial#PPDULCL708504
ESRI Shapefiles can contain only a single type of geometry - Point, LineString, Polygon etc.
Your description suggests that your query returns multiple types of geometry, so restrict that first (using STGeometryType() == 'POLYGON', for example).
Secondly, you're currently returning the spatial field as a text string using STAsText(), but you're not telling OGR that it's a spatial field so it's probably just treating the WKT as a regular text column and adding it as an attribute to the dbf file.
To tell OGR which column contains your spatial information you can add the "Tables" parameter to the connection string. However, there's no reason to do all the casting from WKT/WKB if you're using SQL Server 2008 - OGR2OGR will load SQL Server's native binary format fine.
Are you actually using SQL Server 2008, or Denali? Because the serialisation format changed, and OGR2OGR can't read the new format. So, in that case it's safer (but slower) to convert to WKB first.
The following works for me to dump a table of polygons from SQL Server to Shapefile:
ogr2ogr -f "ESRI Shapefile" -overwrite c:\temp -nln Zip_States -sql "SELECT ID, geom26986.STAsBinary() FROM [Spatial].[dbo].[OUTLINE25K_POLY]" "MSSQL:server=.\DENALICTP3;database=Spatial;trusted_connection=yes;Tables=dbo.OUTLINE25K_POLY(geom26986)"
Try the following command
ogr2ogr shapeFileName.shp -overwrite -sql "select top 10 * from schema.table" "MSSQL:Server=serverIP;Database=dbname;Uid=userid;trusted_connection=no;Pwd=password" -s_srs EPSG:4326 -t_srs EPSG:4326

Visualize text file with location info and intensity

I have an ascii text file containing location data (column 9-lat and 10-long) and intensity(column 20)
200010 207 020311 40658.5 406593 52 344927.31 7100203.50 -26.2078720 127.4491855 345060.64 7100369.14 26.4 650.3 628.0 55471.293 20.168 55648.817 55637.523 -146.062
the text file has many lines 10k+
I am trying to visualize this using GDAL, but not sure how to proceed.
Ideas?
Try QGis. It is free software for making maps with data.
GDAL is for doing sophisticated data transformations.
If your file is named viz.txt, then you can extract
and plot the data using the following commands:
$ awk '{print $9, $10, $20}' < viz.txt > viz2.txt
$ gnuplot
...
gnuplot> plot "viz2.txt" with points palette
This will give you a chart, nicely coloured by intensity.
If you want a more interactive solution, or to overlay the
data on a map, then you will have to use GIS software such
as ArcView, MapInfo or the free tools Generic Mapping Tools (GMT) or QGIS.