Is it possible to export geometry data from a shapefile to CSV from QGIS? - gis

I'm trying to get geometry data from a large quantity of shapefiles into a database (Google Datastore). The thing is, I don't need to work with maps, I just need the coordinates, so I would like just the numerical coordinates. Ideally I'd like to use CSV, but any plain text would be workable. I have a Mac and have been able to get QGIS installed (I also tried udig but the interface was baffling). While it is easy to load a shp file into QGIS as a vector layer, I'm lost as to how to export the geometry, or even if it is possible.
Does anyone know how to extract plain text geometry from a shp file? Ideally with QGIS, but any method would be appreciated.

The "You can simply right-click the layer entry in QGIS and select "Save as"" approach was right
But the "GEOMETRY=AS_WKT" in the OGR layer option was missing.
I may also be a good idea to convert the coordinate system to WGS 84, as CSV are usually expected not to be projected (and shapefile sometimes are)

You can simply right-click the layer entry in QGIS and select "Save as".
In the dialog, there's an option to save as "CSV".
There are plenty of options to refine the format of the generated CSV file, as well as there are many other file formats to choose from.

Update:
See here for a solution: https://gis.stackexchange.com/a/8846
Outdated Response:
It is possible, in a sort of roundabout way...
Open the attribute table for the layer you want to save.
Select all rows.
Copy the rows
Paste into a spreadsheet
Save the spreadsheet as a csv.
Unfortunately there is no way to do this directly in QGIS.
See here for more details:
https://gis.stackexchange.com/questions/8844/get-list-of-coordinates-for-points-in-a-layer/8911#8911

Related

export plots with netlogo

I am trying to export all the plots of my NetLogo model after simulation runs in a csv format with the primitive export-all-plots.
I haven't found yet the way to open this csv file with an external reader in order to get more clear plots. I tried with gnuplot but it looks like it's not able to open the csv format created with NetLogo:
"export-plots data (NetLogo 5.0.5)"
^
"C:\results\interface.csv", line 1: invalid command
How can I open csv plots with an external reader?
There are two complicating factors about NetLogo's plot export format. First, there's a three line header at the beginning (plus an empty line after) that just gives information about the model and when the data was generated. Next, there's data about the model settings, the plot state (pen colors and such). Finally, there's the data itself, which itself is somewhat complicated by the fact that you can have multiple pens per plot. So I'm not surprised gnuplot couldn't read it as is.
The table's are quite easy to use in GUI spreadsheet application, like Excel, LibreOffice's Calc, or Gnumeric. You can just select the data you want and generate the plots.
To do this at the command line, I'm afraid you might have to write a script to read it in. This should be pretty easy in something like Python or R. Just skip the metadata lines, and use a CSV parser to read in the rest.
You might also try using BehaviorSpace to generate the data, but make sure to use the table output. It let's you generate the data from many runs at once, and the format is a little more consistent. There are still 6 lines of metadata at the top, but you can just delete that. I believe this is more the standard practice in NetLogo.

extracting CSV data

I am trying to build a custom map in Tile Mill and am new to programming in general so I apologize is if comes off as uninformed. I've done research but I'm not sure if I'm looking in the right place.
My basic question: this is an embedded map of restaurants in the SF area. Is there a way for me to extract the data for the locations to use in building a custom map of my own?
http://www.sfgate.com/food/top100/2012/map/
It seems that if the location markers exist on a map, that meta data is somewhere, I just don't know how/where to access it....I believe the raw formats for inputting location into a map are CSV or KML and wondering if there is a way to extra these data types from embedded maps.
Thanks!!
View the source of the page in question, look for the data (it's under the variable mapLocs, copy it from the page, and write a little script to convert their format to CSV.
^ this is likely against at least 2 different copyrights (newspaper's & geocoder's), so proceed at your own risk.

Weka Predictions to CSV

I've trained a classifier in Weka, and I'm able to use it on test data. Additionally, I can opt to display the classifier's predictions in the log window for this test data.
However, for my current project, it would be convenient for me to be able to get this data in CSV format. Is this possible in Weka ? Is it only possible when using the command line (something I'll eventually move towards) ?
I could always save the entire buffer result to a text file, but in that case, I would have to parse the file and remove all the "noise" (which isn't really noise, but you get the point).
So, to conclude, is there any way to output Weka's predictions for a test set to a CSV file ?
Edit: as the answer below shows, there is an option to do this. However, it can only be found in Weka 3.7 and above !
I assume you use Weka's Explorer. In the Classify tab click on More options..., then click on Output predictions and select CSV. Now click on the box showing CSV and a window opens where you can fill in the properties of writing to a CSV file. Click on outputFile and select a folder and type a filename (note: you must supply a filename). Running a new test will now save the prediction results to your CSV file.
In Weka 3.6.x you can right-click your model, choose "Visualize classifier errors" and Save the data (including the prediction) from there.
If you use weka knowledge flow to build models (Easier than explorer), there are CSV data sinks you can use to save as CSV file.

Save Google NGram result as .csv

Is there an easy way, to save a Google Ngram result
http://books.google.com/ngrams/
as a csv?
So that I get a list like
1900 peace 500000times
1901 peace 540000times
and so on?
I downloaded their raw data but have no idea how to handle it. When I open those csv in OpenOffice, I can't even see a single word.
It can be done, and it's actually quite easy. Generate the graph you want on the Google Ngram viewer, then use your browser's function to show the page source code (this might be hidden under advanced or developer options). Then in the code (probably on line 297), you will find the data simply listed. You can use any word processor and/or spreadsheet software to clean up the data and export them as CSV.
No, you'd have to go to their datasets, which would be daunting to find what you wanted, or you could try Microsoft Research's N-Gram service.

Best way to overlay an ESRI shapefile on google maps?

What is the best way to overlay a shapefile in Google Maps?
After some reading suggests that, converting shapefile into KML and overlaying KML in Google map is an option. If that is the case, how do I convert a shapefile into KMLs?
I believe there would be a few open source tools available for this conversion. Can anyone point to a tool to covert a shapefile to KML without any loss of data?
I like using (open source and gui friendly) Quantum GIS to convert the shapefile to kml.
Google Maps API supports only a subset of the KML standard. One limitation is file size.
To reduce your file size, you can Quantum GIS's "simplify geometries" function. This "smooths" polygons.
Then you can select your layer and do a "save as kml" on it.
If you need to process a bunch of files, the process can be batched with Quantum GIS's ogr2ogr command from osgeo4w shell.
Finally, I recommend zipping your kml (with your favorite compression program) for reduced file size and saving it as kmz.
as of 12.03.2019 FusionTables is no more...
Import the Shapefile into Google FusionTables ( http://www.google.com/fusiontables ) using http://www.shpescape.com/ and from there you can use the data in a number of ways, eg. display it using GoogleMaps.
I would not use KML. Instead, use GeoJSON which you can natively consume in Google Maps API now. It is a newer feature that didn't exist from the original responses.
In any case, simply open the SHP file in Quantum GIS, and then you can output it in any format you like (KML, GeoJSON).
If you are using Google Maps for Work, I found a premium extension that handles loading shapefiles directly where you can just connect direct to the shapefile that you generate from ESRI. I did a search on the CMaps site and found this snippet which loaded US by state shapefile: https://gmapsplugin.net/cmapsanalytics/assets/shapes/usstates.shp
var cMap = new centigon.locationIntelligence.MapView();
cMap.key([your_api_key]);
cMap.layerNames(["Basic Shapes"]);
cMap.dbfKeys([['Alabama','Alaska','Arizona','Arkansas','California','Colorado','Connecticut','Delaware','District of Columbia','Florida','Georgia','Hawaii','Idaho','Illinois','Indiana','Iowa','Kansas','Kentucky','Louisiana','Maine','Maryland','Massachusetts','Michigan','Minnesota','Mississippi','Missouri','Montana','Nebraska','Nevada','New Hampshire','New Jersey','New Mexico','New York','North Carolina','North Dakota','Ohio','Oklahoma','Oregon','Pennsylvania','Rhode Island','South Carolina','South Dakota','Tennessee','Texas','Utah','Vermont','Virginia','Washington','West Virginia','Wisconsin','Wyoming']]);
cMap.userShapeKeys([['Massachusetts','Minnesota','Montana','North Dakota','Hawaii','Idaho','Washington','Arizona','California','Colorado','Nevada','New Mexico','Oregon','Utah','Wyoming','Arkansas','Iowa','Kansas','Missouri','Nebraska','Oklahoma','South Dakota','Louisiana','Texas','Connecticut','New Hampshire','Rhode Island','Vermont','Alabama','Florida','Georgia','Mississippi','South Carolina','Illinois','Indiana','Kentucky','North Carolina','Ohio','Tennessee','Virginia','Wisconsin','West Virginia','Delaware','District of Columbia','Maryland','New Jersey','New York','Pennsylvania','Maine','Michigan','Alaska']]);
cMap.labels([['Massachusetts','Minnesota','Montana','North Dakota','Hawaii','Idaho','Washington','Arizona','California','Colorado','Nevada','New Mexico','Oregon','Utah','Wyoming','Arkansas','Iowa','Kansas','Missouri','Nebraska','Oklahoma','South Dakota','Louisiana','Texas','Connecticut','New Hampshire','Rhode Island','Vermont','Alabama','Florida','Georgia','Mississippi','South Carolina','Illinois','Indiana','Kentucky','North Carolina','Ohio','Tennessee','Virginia','Wisconsin','West Virginia','Delaware','District of Columbia','Maryland','New Jersey','New York','Pennsylvania','Maine','Michigan','Alaska']]);
cMap.polyDataSources([centigon.locationIntelligence.CMapAnalytics.DATA_PROVIDERS.SHAPE_DATAPROVIDER]);
cMap.layerTypes([centigon.mapping.Layer.TYPE.POLY]);
cMap.locations([["https://gmapsplugin.net/cmapsanalytics/assets/shapes/usstates.shp"]]);
cMap.panTo("USA");
cMap.zoomLevel(3);
Do you mean shapefile as in an Esri shapefile? Either way, you should be able to perform the conversion using ogr2ogr, which is available in the GDAL packages. You need the .shp file and ideally the corresponding .dbf file (which will provide contextual information).
Also, consider using a tool like MapShaper to reduce the complexity of your shapefiles before transforming them into KML; you'll reduce filesize substantially depending on how much detail you need.
Free "Export to KML" script for ArcGIS 9
Here is a list of available methods that someone found.
Also, it seems to me that the most efficient representation of a polygon layer is by using Google Maps API's polyline encoding, which significantly compresses lat-lng data. But getting into that format takes work: use ArcMap to export Shape as lat/lng coordinates, then convert into polylines using Google Maps API.
Just to update these answers, ESRI has included this tool, known as Layer to KML in ArcMap 10.X. Also, a Map to KML tool exists.
Simply import the desired layer (vector or raster) and choose the output location, resolution, etc. Very simple tool.
2018 already... I've found this fantastic online tool http://mapshaper.org/ to convert from ESRI shapefiles to SVG, TopoJSON, GeoJSON.
Here is the explanation of how to use it https://www.statsilk.com/maps/convert-esri-shapefile-map-geojson-format
Fast and straightforward! :)