Tag Info

Hot answers tagged

18

Here's a simple script that uses the OGR python bindings: import ogr,csv,sys shpfile=r'C:\Temp\test.shp' #sys.argv[1] csvfile=r'C:\Temp\test.csv' #sys.argv[2] #Open files csvfile=open(csvfile,'wb') ds=ogr.Open(shpfile) lyr=ds.GetLayer() #Get field names dfn=lyr.GetLayerDefn() nfields=dfn.GetFieldCount() fields=[] for i in range(nfields): ...


15

I once had the same question. The answer is that you put a file in the same folder with the ending csvt. For example your file name is xyzdata.csv you add the file xyzdata.csvt This one you can edit with editor for example. And in it you set the data type like this. "Integer","String","Integer","Integer","String","Real" Integer is now the variable for the ...


11

Since the Lat and Long field values "32.363544","-110.969778" have quotes around them, they aren't really treated as numeric. The display x-y data needs the x and y fields to be numeric. Remove the surrounding quotes and it should work. If you have access to a unix machine grep/sed sure would make this job easier. There are also windows ports of these ...


10

There are 2 immediate options that would best get you where you are trying to go. Your first, and probably easiest option, would be to download Quantum GIS, using the OSGeo4W Installer. Once you have installed that program, follow this tutorial, which covers Importing a .csv file to QGIS. Once you have imported the file, simply right click on the layer ...


10

I was able to export to CSV, using other than a comma, by separating the layer creation options in the Save As.. dialog with linebreaks. Neither comma, nor space-separating them (even when they were in quotes) worked, but the linebreaks did the trick. To emphasize.. THIS APPROACH WORKED (linebreak-separated): GEOMETRY=AS_WKT SEPARATOR=SEMICOLON ...


10

The "Add delimited text layer" tool does not interpret the CSVT. Only "add vector layer" needs a CSVT. Basically, "add delimited text layer" tries to make a best guess and it usually does very well recognizing numeric values. One of the reasons to use "add vector layer" is that "add delimited text layer" requires a geometry column. Does your CSV contain a ...


9

My quick fix is to create the first row all with dummy values, and then delete this row/record after bringing into in ArcGIS. This first row contains representative values or often wildly different values (e.g. alphabetic characters even if the column contains numbers that I want to be text data type) and with the largest number of characters needed for ...


8

Yet another option, this is more of a theory and programmatic one, using arcpy. A polygon can consist not only of a single outer ring with a single inner donut hole -- they can be nested to an arbitrary number of levels. Consider the following: A topologically correct polygon's rings are ordered according to their containment relationship (source). ...


8

Rather than messing with the input file, trying to get everything picture perfect, just use the field calculator to convert the text to a number / real. See the examples below:


8

I have simplified your code and corrected the error by using the da module introduced in 10.1. It greatly streamlines the reading of data using cursors, and used in conjunction with the with command this code should be more stable than if it used the the older method of file access. It works by making a list of all the fields and then removing the fields ...


7

If you convert your shapefile to spatialite, you should be able to do the following: 1) Experiment with SQL to test the output: ex. SELECT col1, col2, col3, AsKml(geometry_column) FROM tab 2) Once you are satisfied with the result, you can export it to CSV format: http://stackoverflow.com/questions/5776660/export-from-sqlite-to-csv-using-shell-script ...


7

Ths may be a bit more complicated, but if my two-cents are worth anything (and if you're using MS Office products), I'd recommend importing your .csv into an MS Access .mdb database as a table. (Note: there is a 2GB size limit for an .mdb database). You can then add that Access .mdb table into your ArcMap document and do a right-click > "Display x,y data": ...


7

PostgreSQL has a column limit of between 250 and 1600 "depending on column types", and supports spatial data and queries with the PostGIS extension. So I would be inclined to do two things: First, where a column represents a category rather than free text, create a separate table with those categories, and replace the column with an integer ID and foreign ...


7

I recently dealt with the exact same issue with Statistics Canada census profile CSV files containing 2172 columns. You can import your csv into an ESRI File Geodatabase (FGDB) if you have access to ArcGIS. According to ESRI, the FGDB format can handle 65,534 fields in a feature class or table. In my case, I was able to import my 2172 column wide CSV file ...


7

A slight departure from the traditional CSV->ArcGIS layer could be to use ogr2ogr to create your shapefile from CSV BEFORE loading it into ArcMap. When using OGR, you can manually create a CSVT file that describes your column types, similar to what ArcGIS attempts to do with the schema.ini file. This post by @underdark on How to Specify Data Types of CSV ...


7

First, you have to load the data into QGIS, and tell it that the data should be treated as EPSG:31467. Normally you do that with right-click -> Set CRS for layer. Then, save the data as shapefile in EPSG:31467, and add the file to the canvas. Check if QGIS has chosen the right CRS: The new layer should align with the old, and rightclick -> Set CRS should ...


7

You will need to do some formatting of your data to make them into polygons. Merely labeling a field as WKT will not help. If you have a lot of files (which it sounds like you do), the most effective way will be to automate your solution by writing a script. I was going to explain how when I decided that the simplest way would be to write an example script ...


7

I would suggest Pleiades as the best option to start with. Lots of data, open source implementation, and you can upload too. You can download in CSV, KML and other formats. You may need to work the links to get supporting data such as population size - I don't know of anything that does that kind of time-varying data across the ancient world. If you ...


7

The simple way to do this, without writing any Python, would be to translate the start and end to a WKT version of the line: Open the csv in Excel or Open Office, or whatever you use Create a new column with the formula: ="LINESTRING(" & A1 & " " & B1 & "," & C1 & " " & D1 & ")" Replacing A1, etc, with your start and end ...


6

If you have FME (or the Data Interoperability Extension in ArcGIS) then the solution looks like this: A CSV reader, 2DPointReplacer transformer, a PointConnector transformer (optional), and a Shape writer. There are some more examples on our FMEpedia knowledgebase. Pros: Easy and visual. Also flexible (there are simple ways to handle data that is not ...


6

I created the following data.csv file: AttributeID 101 101A 101B Then I imported the data using the Table to Table tool: Open ArcMap Expand Catalog window Located data.csv Right click and select Export > To Geodatabase (single)... Specified Output Location to be my Geodatabase (I'm using SDE on SQL Server) Specified Output Table Note that the field map ...


6

the attributes of a shapefile are stored in an extra dbase-file. for example: mypolygons.shp contains geometries, mypolygons.dbf contains attributes. via an id the attributes are connected to the polygons. so just simple load your dbf file into capable software (e.g libreoffice) , edit attributes and your done


6

The pyshp module is a bit tricky to get the hang of, but really useful once you get it going. I've written a script that reads in a csv of the example data and writes out a shapefile with the data stored as attributes of the correct datatypes. The pyshp/xbase datatyping has always been tricky for me until I found this user guide for the xbase format and as a ...


5

I think you were missing closing your output text file - until you do that, you won't get anything written to the text file. Below code tested and works: import arcpy arcpy.env.workspace = r"C:\Users\chad\Documents\ArcGIS\Default.gdb" arcpy.BuildRasterAttributeTable_management("raster17", "Overwrite") outfile = open(r"D:\temp\raster17.txt", "w") rows = ...


5

You're looking at the right question, just not the right answer! The reason that that worked for the answer you were looking at is that the data was only in points. Since your data is in polygons, it won't work. BWill's answer further down is what you need. It will copy all the co-ordinates describing each polygon into WKT format, which is a standard ...


5

Please have a look at the Copy Rows geoprocessing tool. The code can be as simple as the following: import arcpy arcpy.CopyRows_management("C:/data/vegtable.csv", "C:/output/output.gdb/vegtable")


5

Qgis 1.8.0 has a bug in correct encoding of shapefiles. Until this is solved, you can try this workaround in Windows: Browse to C:\Programs\Quantum GIS Lisboa\bin on Windows XP or C:\Programs (x86)\Quantum GIS Lisboa\bin on Windows 7. Look for qgis.bat and open it with a suitable editor (I have installed notepad++ for such things). After line 1, insert: ...


5

I do this using R. There is a package called foreign which enables reading and writing of dbf files. library(foreign) # load the package data <- read.dbf('myfile.dbf') # read the dbf as a dataframe In this case I just wanted to change the rounding of a column pop_den: data$pop_den <- round(data$pop_den) # trim data (removing significant figures) ...


5

I have seen this behaviour in other software when the number of entries in a row doesn't match the number of field headers, or the data type changes at one line (ie a string field finding a numeric entry or visa versa). You would be advised to examine the rows carefully, particularly if you are using a spreadsheet to create the *.csv since mixed data types ...



Only top voted, non community-wiki answers of a minimum length are eligible