Thank you Zoltan!

On 06/08/17 07:05, Siki Zoltan wrote:
> Dear Erik,
> 
> if there is a .prj file to your shape and it is valid you need not to
> use -s_srs.

Yes, there is a .prj file to each .shp (in all zip-archives).

> Only one of -a_srs and -t_srs is neccessary in your case, if
> you want to reproject coordinates use -t_srs. If you want only change
> the projection but not the coordinates use -a_srs.

I want both. So far I (think I) have only managed to change the projection.

Here's the loop where it happens (please note that I expect ogr2ogr to
read and write to the same shpfile):

for shpfile in shapefiles:
    print(shpfile)
    subprocess.call(["ogr2ogr", "-f", "ESRI Shapefile", "-s_srs",
"EPSG:3006", "-t_srs", "EPSG:3006", shpfile, shpfile])

Below is the ogrinfo command line output for one of the records in one
of the shapefiles that originally happens to have EPSG:3008. The record
has OBJECTID=49426 before and after the loop above. As you can see, the
POLYGON coordinates are unchanged.

However, in QGIS the shapefile is displayed under Layer Properties ->
General with SCR as "Selected CRS (EPSG:2006, SWEREF99 TM)".

I hope that there is a way I can tell ogr2ogr to also recalculate the
values of the coordinates. Is there?

Thanks again!

//Erik


(p.s. removing "-s_srs", "EPSG:3006" from the subprocess call in the
loop above makes no difference, the output is the same)


$ogrinfo -ro -where 'OBJECTID=49426' shapefile.shp Byggnad_z

Layer name: Byggnad_z
Metadata:
  DBF_DATE_LAST_UPDATE=2016-12-05
Geometry: Polygon
Feature Count: 1
Extent: (111545.260000, 6153657.656500) - (127881.434300, 6168436.895000)
Layer SRS WKT:
PROJCS["SWEREF99_13_30",
    GEOGCS["GCS_SWEREF99",
        DATUM["SWEREF99",
            SPHEROID["GRS_1980",6378137.0,298.257222101]],
        PRIMEM["Greenwich",0.0],
        UNIT["Degree",0.0174532925199433]],
    PROJECTION["Transverse_Mercator"],
    PARAMETER["False_Easting",150000.0],
    PARAMETER["False_Northing",0.0],
    PARAMETER["Central_Meridian",13.5],
    PARAMETER["Scale_Factor",1.0],
    PARAMETER["Latitude_Of_Origin",0.0],
    UNIT["Meter",1.0]]
OBJECTID: Integer (9.0)
Z: Real (19.11)
Shape_Leng: Real (19.11)
Shape_Area: Real (19.11)
OGRFeature(Byggnad_z):49425
  OBJECTID (Integer) = 49426
  Z (Real) = -9999.00000000000
  Shape_Leng (Real) = 32.97354794050
  Shape_Area (Real) = 66.76357026070
  POLYGON ((113489.4814 6163235.5459,113485.7853
6163228.8576,113479.6167 6163232.2701,113479.6002
6163232.3537,113483.2085 6163238.9869,113483.1822
6163239.0013,113484.0331 6163240.5029,113490.3152
6163237.0547,113489.4814 6163235.5459))


Layer name: Byggnad_z
Metadata:
  DBF_DATE_LAST_UPDATE=2017-08-06
Geometry: Polygon
Feature Count: 1
Extent: (111545.260000, 6153657.656500) - (127881.434300, 6168436.895000)
Layer SRS WKT:
PROJCS["SWEREF99_TM",
    GEOGCS["GCS_SWEREF99",
        DATUM["SWEREF99",
            SPHEROID["GRS_1980",6378137,298.257222101]],
        PRIMEM["Greenwich",0],
        UNIT["Degree",0.017453292519943295]],
    PROJECTION["Transverse_Mercator"],
    PARAMETER["latitude_of_origin",0],
    PARAMETER["central_meridian",15],
    PARAMETER["scale_factor",0.9996],
    PARAMETER["false_easting",500000],
    PARAMETER["false_northing",0],
    UNIT["Meter",1]]
OBJECTID: Integer (9.0)
Z: Real (19.11)
Shape_Leng: Real (19.11)
Shape_Area: Real (19.11)
OGRFeature(Byggnad_z):49425
  OBJECTID (Integer) = 49426
  Z (Real) = -9999.00000000000
  Shape_Leng (Real) = 32.97354794050
  Shape_Area (Real) = 66.76357026070
  POLYGON ((113489.4814 6163235.5459,113485.7853
6163228.8576,113479.6167 6163232.2701,113479.6002
6163232.3537,113483.2085 6163238.9869,113483.1822
6163239.0013,113484.0331 6163240.5029,113490.3152
6163237.0547,113489.4814 6163235.5459))




> Best regards,
> Zoltan
> 
> On Sun, 6 Aug 2017, Erik Josefsson wrote:
> 
>> Hello,
>>
>> I have a handful of zip archives containing original shapefiles with
>> different coordinate reference systems (e.g. SGER:3008 and SGER:3021).
>>
>> I want to extract and convert them all to SGER:3006 and thought that
>> ogr2ogr would do the job, but I don't find intelligible instructions on
>> how to use the srs-parameters: -s_srs, -t_srs and -a_srs.
>>
>> Do I have to know the coordinate reference system of each original shape
>> file to use ogr2ogr successfully? If so, how do I retrieve that
>> information?
>>
>> Or should I just override the original coordinate reference system like
>> this?
>>
>> ogr2ogr -f 'ESRI Shapefile' -s_srs EPSG:3006 -t_srs EPSG:3006 -a_srs
>> EPSG:3006 A.shp B.shp
>>
>> Best regards.
>>
>> //Erik
>>
>>


Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
Qgis-user mailing list
Qgis-user@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user

Reply via email to