4

I had an excel spreadsheet that included latitude and longitude coordinates for a series of points. I created a shapefile in QGIS from this data and selected the correct CRS (NAD83 / Massachusetts Mainland / EPSG:26986 / units = meters).

Now I want to export the data back into a CSV Excel file with the coordinates listed in meters (not latitude and longitude). But every time I right-click the vector file and Save-As, the WKT coordinates are displayed as latitude and longitude.

Is there something I'm doing wrong in QGIS?

  • Were your original coordinates in the excel file in decimal degrees or EPSG:26986? – DPSSpatial Oct 11 '17 at 21:16
  • QGIS used to have a bug with 'Save As', if you chose the same as the coordinate system of the canvas (project) it did not apply it. Try the same process but use as specified and select the output coordinate system as EPSG:26986. This of course needs the input coordinate system to be chosen correctly, if your points' coordinate system is undefined the Save As process will do absolutely nothing, be sure to set your layer CRS to the geographic coordinate system the points are in. – Michael Stimson Oct 11 '17 at 21:19
  • @DPSSpatial they were in decimal degrees. Such as 42.5181, -71.1319 – csft306 Oct 11 '17 at 22:24
  • 1
    @cw305 what I would do is create the shapefile first in WGS84, then Save as > then re-project the entire file to EPSG:26986. Then when you save that back out as a CSV, your WKT coordinates will be in EPSG:26986... – DPSSpatial Oct 11 '17 at 22:53
  • @DPSSpatial I think your comment is worth a full answer. – AndreJ Oct 13 '17 at 14:49
5

What I would do is create the shapefile first in WGS84. This creates a shapefile with geometry in WGS84 Decimal Degrees, and a good starting point for any dataset that originates from decimal degree coordinates.

Then, create a new copy of your data in EPSG:26986 by right-clicking the layer, Save as > then set the CRS to EPSG:26986.

Then when you save the projected layer back out as a CSV, your WKT coordinates will be in EPSG:26986.

0

Maybe not the answer you are looking for if you are strict about doing this in QGIS, but I do these kind of conversions in PostgreSQL/PostGIS. It is easy to install if you don't have it and makes life much easier when dealing with geometry, at least for me.

First create schema data as you don't want to put your data in public schema:

CREATE SCHEMA data;

Then create the table:

    CREATE TABLE data.table_name
(
  id serial NOT NULL,
  lat double precision,
  lon double precision,
  other_field text,
  geom geometry(Point,26986),
  CONSTRAINT table_name_pkey PRIMARY KEY (id)
)

You can include more fields according to your input file, just use correct types. Next step is to import the data into the table:

COPY data.table_name(lat,lon,other_field) FROM '/home/dejan/test.csv'  DELIMITER ',' CSV HEADER;

Of course, use your fields and path. Use HEADER if you have header in your input, like in my sample:

lat,lon,other_field
23,-79,test1
23.5,-79.5,test2

Create the geometry with desired EPSG:

UPDATE data.table_name set geom=ST_Transform(ST_SetSRID(ST_MakePoint(lon, lat),4326),26986);

And now you can convert to any EPSG available in PostGIS or custom added and export the coordinates:

select ST_X(geom) as long, ST_Y(geom) as lat, other_field from data.table_name;

pgAdmin can help you with some of these steps through graphical interface.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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