1

I have a set of points which represent the bottom left corner of a 50x50 meters grid. Could you please let me know if there is a way to build a polygon/square from this point to represent the 50x50 area?

There are over 10,000 points in the file.

My point data is in Latitude and Longitude.

user82635
  • 153
  • 1
  • 1
  • 7
  • Welcome to GIS:SE @geejay! Perhaps this post might help: How to create square buffers around points in QGIS with Python? – Joseph Sep 15 '16 at 11:11
  • Maybe a duplicate of http://gis.stackexchange.com/questions/210295/how-to-create-square-buffers-around-points-in-qgis-with-python. – user30184 Sep 15 '16 at 11:12
  • Thanks both - unfortunately, it asks about having the centre in the centroid position which I am able to figure out, but not sure how to progress with a polygon where the point is at the corner of each polygon to be created. – user82635 Sep 15 '16 at 11:14
  • Have you tried ' Vector > Research Tools > Vector Grid'. You can then you the points layer as the grid extent with a 50m spacing and output as polygons – Knightshound Sep 15 '16 at 11:17
  • @Knightshound I need the polygon to 'have' the point at its bottom right corner. The points are not uniform/complete, so there may be 20 points spread across a city, and I need a 50x50 polygon where the point is at the bottom right corner.

    A vector grid would just place a grid over the entire canvas/selection.

    – user82635 Sep 15 '16 at 11:21
  • You will build a polygon from the starting point and offsets to left-up-right-down. I believe that I have written an answer to similar question by using SQL. – user30184 Sep 15 '16 at 11:29

2 Answers2

4

It can be done without to much code, even in a good old spreadsheet program. But to do so with QGis: The idea is to build a WKT, well known text out of it. You have the lower left of a square and need the other 4 points to build a geometry (start and endpoint needs to be onto each other). As it is a square its easy with simple math. You add 50 to the x-coordinate, then 50 to both x and y and so on. The rules for formatting a wkt can be found here : https://en.wikipedia.org/wiki/Well-known_text

You end up with the following you put into the field-calculator for a new text field (set it to a length of 254, as the maximum for a shapefile and sufficient here):

'POLYGON ((' ||  $x  || ' ' ||  $y  || ', '||  ($x+50)  || ' ' ||  $y  || ', '||  ($x+50)  || ' ' ||  ($y+50)  || ', '||  $x  || ' ' ||  ($y+50)  || ', '||  $x  || ' ' ||  $y  || ', ' || '))'

It is just some text concatenation to build the wkt. You then export your layer to a csv. And load it as a text via "Layer menue - Load layer from textfile" You set it to comma seperated and choose "Well-Known-Text" at geometry definition and your text field you created earlier. Choose the correct coordinate reference when Qgis asks you after loading.

Added some pictures for better clearance (sorry for the german qgis, but the idea should be possible to follow):

enter image description here

enter image description here

enter image description here

enter image description here

Matte
  • 6,235
  • 13
  • 18
  • Thanks for this Matte. Adding the 50 to x, y etc. just bumps up my coordinate number by 50 - it doesn't change it to 50m ? – user82635 Sep 15 '16 at 13:10
  • Try to understand how the polygon is constructed from WKT. Is takes your original point as start vertex, bumps up coordinates and puts the second vertex there and so on, till the fifth vertex that is closing the polygon. – user30184 Sep 15 '16 at 13:34
  • I understand that. My question is that the bump doesn't seem to be distance but rather the literal value of the coordinate. This is because when I use the field calculate before exporting, the export is actually the direct coordinates?

    Or have I got the step of exporting wrong?

    – user82635 Sep 15 '16 at 13:39
  • If your coordinate system is using meters as units changing the coordinate value by 50 moves the point 50 meters. If you use a system that is using degrees as units the movement is 50 degrees. Coordinates are the way how the physical location of the feature are expressed with numbers. I do not quite understand what you mean with "literal value of coordinate". If you are 2 meters tall and someone is stretching you 3 meters tall the literal value or the z coordinate of your head is bumped by 1 meter but you should feel something physical as well. – user30184 Sep 15 '16 at 13:53
  • Thanks for your comments.

    To illustrate - as I input the field calculator formula, the output is given as:

    382500 812900 (my OS grid reference), 382550 812900, 382550 812950

    So the increase in 50 in the OSGrid reference is not the same as 50m distance. My coordinate system is 'correctly' set to EPSG:7405.

    Really appreciate your help.

    – user82635 Sep 15 '16 at 14:05
  • 382550-382500=50, 812950-812900=50. What makes you think that the difference is not 50 m to the east and 50 meters to the north? – user30184 Sep 15 '16 at 14:10
  • Because that's not how Eastings and Northings work.

    I converted the coordinates to Lat/Long, and I am now shown -2.29,57.2; 47.7,57.2

    As you might be able to tell, 50 m from -2.29 is not 50m? :/

    – user82635 Sep 15 '16 at 14:38
  • Because that's not how Eastings and Northings work.

    I converted the coordinates to Lat/Long, and I am now shown -2.29,57.2; 47.7,57.2

    As you might be able to tell, 50 m from -2.29 deg is not 47.7deg? :/

    – user82635 Sep 15 '16 at 14:44
  • Coordinates are only numbers. How you interpret them means what is happening. And your system is a transverse mercator with meters as units (a cylindrical projetion to cartesian coordinates). And that means that adding 50 to the x of a point is moving this point 50 m to the east. – Matte Sep 15 '16 at 15:00
  • I am really sorry for asking for help, but I can sense that we are so close to the answer. Could you please let me know if it is the coordinate system I am using that's the issue (lat/long, northing easting) - should it be something else that's treated arbitrarily?

    Matte - when I put 50 to the $x, it adds 50 as a number to the longitude value. That's not right is it! Am I missing something?

    – user82635 Sep 15 '16 at 15:00
  • Please edit your question and tell people that your points are in latitude/longitude degrees and you want to compute boxes in meters. That makes the work flow different: re-project the point into some suitable meter based projection, compute the boxes as you have been told, and re-project the boxes back to the original longitide-latitude system. – user30184 Sep 15 '16 at 15:03
  • Thanks very much all of you. This solution worked for me, and user30184's valuable suggestion of converting to a meter based projection for the above WKT formula helped. – user82635 Sep 18 '16 at 20:24
1

You can use 'Vector > Research Tools > Vector Grid' to create a single square polygon from a point in the bottom right corner. The example below use a point at 0,0 to better understanding how to set the grid extents but essentially to create a 50m box with the point in the bottom right corner you must set

xmin = -50m from point x coordinates

xmax = -25m from point x coordinates

ymin = 25m from point y coordinate

ymax = 50m from point y coordinate

enter image description here

Knightshound
  • 4,430
  • 18
  • 39
  • Thanks for your reply Knightshound. I must have clarified that there are over 10,000 points (not just 1). I am assuming your method only draws the polygon for a single point? – user82635 Sep 15 '16 at 11:55
  • Sadly it does. It's best when asking a question to have as much information about your situation as possible. I would have to guess that python needs to be used here – Knightshound Sep 15 '16 at 12:00
  • I should have been more clear then.

    Are there any tools or code available to make this happen?

    – user82635 Sep 15 '16 at 12:34