VectorReprojector

Reprojects a vector, or all the vectors of a folder, to another coordinate reference system, as the data of a national grid to UTM or to lat/long for a web map. A vector without crs, or with a wrong one, can be given its crs first.

Details

The vertices are transformed one by one, so a long straight segment stays straight in the new crs, where it should become a curve: the long lines need more vertices first if their shape matters, as the vertex spacing of GridsGenerator gives to its grids. The attributes don’t change: the lengths and the areas stored in the fields keep the values of the original crs.

A vector without crs, or with a wrong one, as a shapefile without its prj, can be given its crs with the force code, before the reprojection. The force code doesn’t move the geometries.

Between crs on different datums the transformation needs the datum shift parameters (TOWGS84, Bursa-Wolf), that the EPSG database has for most of the national datums. When they are missing, the lenient mode reprojects anyway ignoring the datum shift, with errors that can reach some hundred meters; without it, the reprojection stops.

A lat/long output has the longitude as first axis, as x, the order of the shapefiles and of most GIS. Setting the longitude first switch to false gives instead the order of the EPSG definition, the latitude first for EPSG:4326, as some standards require.

Parameters

Reprojects a vector to another coordinate reference system.

Toolbox folder: Vector Processing
Status: Certified
Keywords: CRS, Reprojection, Vector
Authors: Andrea Antonello
Class: org.hortonmachine.modules.VectorReprojector

Inputs

Parameter

Type

Unit

Default

Description

inVector

vector file

The vector that has to be reprojected, or with the wrapper a folder of vectors.

pCode

CRS code

The code defining the target coordinate reference system, composed by authority and code number (ex. EPSG:32632).

doLongitudeFirst

Boolean

The longitude as first axis of a lat/long output (default); false for the axis order of the EPSG definition, the latitude first for EPSG:4326.

pForceCode

CRS code

An optional coordinate reference system to give to the input vector, if it has none or a wrong one, composed by authority and code number (ex. EPSG:3003).

doLenient

boolean

true

Switch that set to true allows for some error due to different datums. If set to false, it won’t reproject without Bursa Wolf parameters.

Outputs

Parameter

Type

Unit

Description

outVector

output file

The output reprojected vector.

Example

The example reprojects the sub-basins of BasinShape, in the crs of the sample elevation model, Monte Mario / Italy zone 1 (EPSG:3003), to UTM 32N on WGS84 (EPSG:32632):

import org.hortonmachine.modules.VectorReprojector

// the folder with the elevation model: change it to yours
var folder = "/data/flanginec/"

var reprojector = new VectorReprojector()
// the sub-basins of BasinShape, in Monte Mario / Italy zone 1 (EPSG:3003)
reprojector.inVector = folder + "subbasins.shp"
// to UTM 32N on WGS84
reprojector.pCode = "EPSG:32632"
reprojector.outVector = folder + "subbasins_utm.shp"
reprojector.process()

The bounds of the sub-basins, before and after:

crs

west

east

south

north

EPSG:3003

1638650.0

1640330.0

5112520.0

5114210.0

EPSG:32632

638619.3

640299.3

5112499.0

5114189.0

The two grids are both transverse Mercator projections with the same central meridian, on different datums: the coordinates differ by the 1000 km of the different false easting and by the datum shift, here 31 m west and 21 m south, the same, to the centimeter, that PROJ computes.