2

By copying rows of the attribute table of a polygon shapefile, I figured out how to extract the points of the given polygon but to my surprise, they are formatted backwards:

POLYGON((
-87.529571533203125 34.55934906005859375,
-87.52953338623046875 34.3049163818359375,
-87.93964385986328125 34.31328964233398438,
-88.17311859130859375 34.32147979736328125,
-88.1404571533203125 34.58187484741210938,
-87.95177459716796875 34.57530975341796875,
-87.52912139892578125 34.56753158569335938,
-87.529571533203125 34.55934906005859375))  

Is there a way to export these points in the same way but formatted as lat/lon xx.xx, -xx.xx points?(only US counties are being processed).
If not and post-formatting is the only option, if there is anyone out there who has already done this...how?
If not I guess I will just have to write a formatting script but it will be a pain to execute on all 4703 counties.

7
  • Backwards according to who? What is the intended end use?
    – Willy
    Commented Nov 3, 2013 at 23:02
  • I always thought the standard format was lat/lon but the shapefile exports them as lon/lat coordinates. The points will eventually be used in another program that takes strictly formatted files with points in lat/lon format, not lon/lat format. Commented Nov 3, 2013 at 23:11
  • 2
    In fact, the standard is {X,Y}, which equates to {longitude,latitude}. Well-Known Text also calls for X,Y orientation. I'd have to wonder about any tool that strictly formats data in the reverse of standards.
    – Vince
    Commented Nov 4, 2013 at 2:27
  • I am using the points for application in meteorology. Almost all if not the entirety of all meteorological text statements format points as lat/lon pairs. Knots are also used opposed to km/h or mph so I guess it may be somewhat of an outlier. Commented Nov 4, 2013 at 3:18
  • I figured it out. Installing the plugin 'Swap XY' does the trick. Commented Nov 4, 2013 at 21:15

2 Answers 2

3

Use MMQGIS plugin

It is available from the Manage and Install Plugins item, search for mmqgis

These tools will appear with their own menu item MMQGIS, use the Import / Export | Geometry Export to CSV.

Two files will be created. You want the "nodes"

Once you have this new file in a spreadsheet, move the columns around. Then the next steps depend on the import requirements of your program. Look at the structure of the nodes file created by MMQGIS and note how the shapeid column gives an index of the polygons.

6
  • This is certainly progress...I end up with a 'shapeid' column, a 'y' column, and an 'x' column. Each y,x pair is unique but there are many, many rows with the same 'shapeid'. Is there a way to combine all the y,x pairs with the same 'shapeid'? Commented Nov 3, 2013 at 23:34
  • For instance some CAD software will do that as it is imported. What format exactly does your target software need for import?
    – Willy
    Commented Nov 4, 2013 at 1:40
  • The desired format is lat1, lon1 lat2, lon2 lat3, lon3 etc. with each pair on it's own line. Commented Nov 4, 2013 at 1:53
  • How are polygons grouped?
    – Willy
    Commented Nov 4, 2013 at 11:03
  • The only requirement is that each polygon and it's points be distinct and not blended together. There can be multiple polygon elements in one file or they can be split up to one polygon per file. Commented Nov 4, 2013 at 21:05
0

Organise the data in the shapefile first.

You can create new fields in the attribute table, one column for each of x and y. If you copy that into a spreadsheet program, you will may get the WKT data in the first column then the new columns to the right of that. You can delete the superfluous data until you are left with the columns of interest.

So open the attribute table up, toggle editing on, click on the Field Calculator icon (like an abacus), create new fields with the expression as $x and another with $y (from the Geometry set in the Functions List). Set the precision of the new field to Decimal Number (real) with a field width of 10 and a precision of 10.

If you do need the x and y in the same field/cell as text, you could concatenate the $x to the $y, probably you would want a space in between, so the expression would be:

$x || ' ' || $y

Let us know how you go.

5
  • Obviously you can reverse the y and x. Also, with the text tools, you could parse out the -ve sign etc.
    – Willy
    Commented Nov 3, 2013 at 23:12
  • Where are the text tools? Sorry I'm very new to qgis. Also would it be possible to, instead of deleting them, to just switch the order? Commented Nov 3, 2013 at 23:15
  • Opps sorry, I see you want a polygon, not a point feature. Will reconsider.
    – Willy
    Commented Nov 3, 2013 at 23:16
  • Indeed, when I tried this the only output was a column of NULL values. It has to be possible somehow. Commented Nov 3, 2013 at 23:19
  • This seems to be a somewhat common question: gis.stackexchange.com/questions/26126/… gis.stackexchange.com/questions/73545/… How should the python script linked in the first answer of the first question be run? Commented Nov 3, 2013 at 23:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.