# Determining coordinates of a SHP file

i have a SHP file of a building converted from a DXF file. This SHP file is unprojected and have no specific coordinates (origin 0,0). I find WGS84 coordinates (lat, long) of this building from Google Maps. My aim is to replace these coordinates to the SHP file on QGIS. Could you explain the process step by step?

(I read lots of similar questions, about affine transformation. But i don't know the paramaters.)

What i ask is how to make this transformation in QGIS (step by step)?

SHP file coordinates (not projected)

Scale: 1:142.670.713

X1,Y1: 16.70824, 253.74534

X2,Y2: 1.03521,-6.34918

X3,Y3: 244.00248,-7.49189

Target WGS84 coordinates

X1,Y1: 41.047773, 28.896241

X2,Y2: 41.045452, 28.895929

X3,Y3: 41.045436, 28.899039

I need a second vector layer with coordinates. I have just a SHP file of a building converted from a DXF file. That is not projected. I know where this building is, and can find the WGS84 coordinates from Google Maps. My aim is add WGS84 coordinates to this SHP file and export to replace the building on Google Maps.

My Questions are:

1) I think my SHP file has measurements in meters and unprojected. I have WGS84 lat long coordinates from Google Maps. How can i project this SHP file, for being ready to transformation? Right Click -> Set Layer CRS -> Choose WGS84 EPSG: 4326. Is this enough?

2) qgsAffine plugin just need transformation matrix paramaters. But the answer of @Jochen Schwarze is a bit complex for me. Is there a online calculator? (Just give the source XYs and target XYs and calculate the parameters.)

I think, I have a projection problem before affine transformation. I have a DXF file of a building from AutoCAD. I saved this DXF file as a SHP file in QGIS. But this SHP file is converted from a plain DXF file and is not referenced/projected, it is drawn from coordinates 0,0 in AutoCAD in meters. And the drawing has meters, WGS84 has decimal degrees.

When I set Layer CRS as WGS84 in QGIS, the coordinates don't change.

How can I project this SHP file as WGS84 in QGIS?

• If your building should be the Forum Istanbul, you better swap X and Y WGS84 coordinates. Otherwise you will end up in the Arabian desert. Jun 7, 2016 at 5:57
• You can do this as an excercise following the calculation steps below :-) Jun 7, 2016 at 7:26

Have a look at How to georeference a vector layer with control points?, in particular the answer concerning the Vector Bender plugin for QGIS. Watch the video and try the plugin, report back if you encounter any issues.

• nice plugin, very cool music :-) Jun 7, 2016 at 10:37

I think you have to carry out three transformations, wich are all affine transformations: scale, rotate and translate. I suggest reading about affine transformation on wikipedia: https://en.wikipedia.org/wiki/Affine_transformation

If you basically can carry out an affine transformation, then this might help you to determine the correct parameters: http://docs.safe.com/fme/2016.1/html/FME_Desktop_Documentation/FME_Transformers/Transformers/affiner.htm

The mathematically basics are not restricted to this FME-tool, but (without any comercial interest) I'd say, I like the implemetation.

So from your 3 pairs of points (x',y',x,y) by considering the definition of affine transformation (eq. (1))

``````x' = Ax + By + C
y' = Dx + Ey + F
``````

gives you a linear equation system with 6 variables:

``````x1' = x1 * A + y1 * B + 1 * C + 0 * D + 0 * E + 0 * F
y1' = 0 * A + 0 * B + 0 * C + x1 * D + y1 * E + 1 * F
x2' = x2 * A + y2 * B + 1 * C + 0 * D + 0 * E + 0 * F
y2' = 0 * A + 0 * B + 0 * C + x2 * D + y2 * E + 1 * F
x3' = x3 * A + y3 * B + 1 * C + 0 * D + 0 * E + 0 * F
y3' = 0 * A + 0 * B + 0 * C + x3 * D + y3 * E + 1 * F
``````

replacing the x, y, x' , y' with your coordinates you have the extended coefficient matrix:

``````41.047773 16.70824 253.74534 1 0 0 0
28.896241 0 0 0 16.70824 253.74534 1
41.045452 1.03521 -6.34918 1 0 0 0
28.895929 0 0 0 1.03521 -6.34918 1
41.045436 244.00248 -7.49189 1 0 0 0
28.899039 0 0 0 244.00248 -7.49189 1
``````

to solve this you need little python (make use of python numpy module):

http://docs.scipy.org/doc/numpy-1.10.1/reference/generated/numpy.linalg.solve.html

``````import numpy

a = [[16.70824, 253.74534, 1, 0, 0, 0],
[0, 0, 0, 16.70824, 253.74534, 1],
[1.03521, -6.34918, 1, 0, 0, 0],
[0, 0, 0, 1.03521, -6.34918, 1],
[244.00248, -7.49189, 1, 0, 0, 0],
[0, 0, 0, 244.00248, -7.49189, 1]]

b = [41.047773,28.896241,41.045452,28.895929,41.045436,28.899039]

numpy.linalg.solve(a,b)
``````

testing this on the python console in QGIS should deliver

``````array([ -2.38763793e-08,   8.92511774e-06,   4.10455087e+01,
1.28020915e-05,   4.28122961e-07,   2.88959185e+01])
``````

these are the 6 transformation parameters A,B,C,D,E,F in eq. (1), cp. above.

If you try another pair of values x,y,x'y' putting x and y in the eq. (1) should deliver x' and y'.

as a python function:

``````def affine(x,y,A,B,C,D,E,F):
xnew = A*x + B*y + C
ynew = D*x + E*y + F
return (xnew, ynew)
``````

As a first guess, you can create a custom transverse mercator projection on one of you coresponding points. Preferably the one closest to the DXF origin:

`````` +proj=tmerc +lat_0=41.045452 +lon_0=28.895929 +k=1 +x_0=1.03521 +y_0=-6.34918 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs
``````

lon_0 and lat_0 are the degree coordinates in WGS84, and x_0 and y_0 the meters coordinates from the DXF.

You can add your meter and degree coordinates as delimited text, assigning the custom CRS for the first and EPSG:4326 for the second. Note that QGIS expects longitude-latitude order for degree coordinates.

This will put at least one point (here No. 2) on the right spot. For use of the Vector bender plugin, it is necessary that both layers are shapefiles and have the same CRS. So you can use `Save As ...` to a new filename and the local UTM zone 35N EPSG:32635 on both layers.

With the Vector bender plugin, you can now connect the "meters" and "degree" points to get the transformation. If your control points get shifted correctly, you can do the same with the whole DXF layer.