Hot answers tagged

23

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): ...


19

I'd recommend using OGR/GDAL, which is part of the GDAL library. OGR supports a virtual format which allows specification via an XML file. If you convert your Excel worksheet into a CSV, you can generate a VRT to access the data. Assuming you have something like this example.csv: Lat,Long,Year,Name 34.0,-120.0,2010-05-01,Off Santa Rosa Island You can ...


16

This works for me, using the arcpy.da.Walk function at ArcGIS 10.1 SP1: import arcpy, csv, os workspace = r"c:\GISData" output = r"C:\temp\test.csv" with open(output, 'wb') as csvfile: csvwriter = csv.writer(csvfile) for dirpath, dirnames, filenames in arcpy.da.Walk(workspace): for filename in filenames: desc = ...


15

Introduction Because this issue (of discrepancies in standard deviations, variances, or other statistical summaries) comes up periodically, especially when a thoughtful and careful GIS analyst checks their work, I thought it would be good to share the "forensic analysis" of the discrepancy so that readers can carry out similar checks in their own ...


14

I've used Open Office for working with dbf files.


13

If you are going to ArcMap 10.1 you could create a python add-in. The add-in gives you access to an "on open" function that will run code when you open the mxd. The help here explains how to create one and has a sample that adds a base layer to the mxd when opening.


12

Install the XY Tools plugin by Richard Duivenvoorde. Select a vector file from the ToC (that is, make it active). Go to Vector->XY tools->Save attribute table as Excel file. You would need the Python library xlw installed for doing so.


10

All of the trigonometric functions you need are in the math module. I presume you'll want atan2() which is the equivalent of atan(y/x). For the mod function, you'll need to use the percent symbol. Each function also has a simplified version (a) since you are calculating some constants. They're identical functions but will be faster. Parser: Python ...


9

For opening and editing, Open Excel 2007 and simply drag the dbf file to it. To create a new DBF file (http://www.excelforum.com/excel-2007-help/643473-save-as-dbf.html): In Excel 2007, Go to "file > Save As.." and choose .csv Now open Access 2007 and Choose import data and select the csv file The data then loads into a table and from there you can export ...


9

Like whuber says, you have to write out the headers explicitly. I loaded up dbfpy and xlwt in a virtualenv and ran this: from xlwt import Workbook, easyxf import dbfpy.dbf from time import time def test1(): dbf = dbfpy.dbf.Dbf("pipelines.dbf", readOnly = True) header_style = easyxf('font: name Arial, bold True, height 200;') book = Workbook() ...


9

When you use Python, you must use the correct modules to do what you want. To find all files in a directory with extension shp, for example, there are much simpler solutions that was presented without the break, which is awful...(as the solution presented by Nathan W, but there are many, many others, just search on Internet) Some examples with relevant ...


9

To get a csv file of the attribute table, rightclick on the layer in the legend, select Save As ..., and change the file format from shapefile to CSV. You might need to change the separator from comma to semicolon in a text editor if Excel does not like the default separator.


9

You could use the Group Stats plugin from Plugins > Manage and Install Plugins. This calculates various data statistics for your attributes such as finding the minimum value in a group. I made an example of attributes from the data you gave: Then from the Group Stats interface, select and drag the toid field from the list into the Rows window; and repeat ...


9

No idea what happened with the first three lines but the other lines are coordinates in UTM zone 28N. data_lat is X, data_lon is Y. I noticed that simply plotting each pair as X and Y points looked very similar, so I gave it a try on http://projfinder.com with success.


8

Do you receive the same error by copy/pasting records? This is from memory, but if you right-click on the gray row indicator box, your menu should have "Copy Selected Records". Then you can paste directly into an Excel spreadsheet. A caveat: if your selections are in a related table that are a result of a feature selection, you might actually have ...


8

I've seen this behaviour as well. If Zachary's solutions don't work (which have usually worked for me in the past), the other thing to try is to export the Excel sheet to a DBF and join that instead. I've only done this in ArcGIS, your results may vary depending on what software you're using.


8

You could use the Delimited Text plugin that comes with QGIS (http://qgis.org) to load the text file and then save it as a shapefile.


8

Assuming the columns appear in time order, the first row (for example) indicates that total construction through each period went 0, 0+45 = 45, 45+135 = 180, 180+405 = 585, 585+1010 = 1595, ..., 2230+0 = 2230. Construction was halfway through at 2230/2 = 1115. This occurred during period 4, because at the end of period 3 the total was 585, at the end of ...


8

Threading doesn't work with most UI manipulation in Windows as UI elements have thread affinity, which is probably why the map view is failing to refresh. I've got a Python project that does this in ArcGIS without threading on Github. It uses the Win32 event loop in the main thread to do timed calls in an add-in extension. You can also use it independently ...


8

Given a list of geographic coordinate pairs, you can implement the Haversine formula directly in Excel. The simplest way to use this (or a more accurate, but I think it's not your case) formula consists into press Alt+F11 to open the VBA Editor, click Insert --> Module and then (copy and) paste e.g. the code kindly suggested by blah238. There will be a ...


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

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


7

This excellent tutorial explains how to do just that. Note that if your data is in UTM: You can follow the same process, but choose the appropriate UTM CRS in the Coordinate Reference System Selector instead of WGS84.


7

If you already have your data in excel make sure of the following a)Data must be in decimal degrees b)First row of the file has the name of the field (this is just an example) then you have to save the file as a csv comma delimited (not msdos or mac). After opening Qgis you have to look for the "add delimited text layer plugin (a blue postit with commas ...


7

Try ET Geowizards Generate (Import from Text) and use a Box type. If new to this free (some tools only) ArcGIS addon, go to http://www.ian-ko.com. For this you need to do a some simple formatting of your excel to be id,xmin,ymin,xmax,ymax - formatting is explained in the tool help.


7

If you don't need some kind of routine or script, here is the simple procedere using QGis (Master 1.9, but 1.8 should also work). Add your shapefile as vector layer in QGIS Add your table (can be .csv or .xls files) to QGis in the same way -> Add Vector Layer Both, table and layer should now be visible in the layer table of contents. Now make a simple Join ...


7

This is expected behavior. The ESRI Maps for Office help references this: Heat map layers and layers that are clustered cannot be shared to ArcGIS Online as a layer, but can be shared as part of a map. In the ArcGIS.com Map Viewer, the heat map layer displays as a point layer instead of rendering as a heat map. Source


6

I looked for but could not find a help page on Display XY Data in the web help but the process is simple. Use Add Data (or drag and drop from Catalog window) to browse for your worksheet (within the spreadsheet) and add it to your map Right-click to choose and use Display XY Data to add an event layer Right-click on the event layer just created and use ...


6

You can control your tabular data with XYtools plugin. The aim of the xy-tools-plugin is to fill an x- and y-column of a given attribute table by clicking on a (reference) map. After 'filling the x and y column' you are able to export the table to a point shape file. Since version 0.2 you can also open Excel files, and using an x- and y-column ...


6

Have a look at Geonames and its free web services. The service you will most likely want to use is its full text search service. Have a look at the documentation and examples and see how far you can get. If you don't know how to use a web API, or know how to populate a spreadsheet, you might ask (or search first) at StackOverflow. See also other questions ...



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