[Qgis-user] Create rectangle with minLat,maxLat,minLon,maxLon

Micha Silver Micha at arava.co.il
Sun Feb 7 04:47:57 PST 2016


Here's a way to do it with Spatialite:

Suppose I have a CSV file of corner coordinated, x1, y1, x2, y2, I import it
into a Spatialite DB as a new table "coords".

Now I create the rectangles table and make it a polygon spatial table:
CREATE TABLE rects (id integer primary key autoincrement);
SELECT AddGeometryColumn('rects','geometry',2039,'POLYGON',2);

Next I use the function PolyFromText to insert rectangular polygons into the
"rects" table. I need to create a WKT POLYGON string. This is tricky since I
need to chain together (with the concat operator: ||) the values from the
coords table, with all commas and spaces as *strings* in the right place.
Here's how it looks:

INSERT INTO rects(geometry)
SELECT 
PolyFromText("POLYGON(("||x1||" "||y1||","|| x2||" "|| y1||","||x1||"
"||y2||","||x2||" "||y2||"))",2039) 
FROM coords;

The final parameter to PolyFromText() is the CRS EPSG code.

HTH



--
View this message in context: http://osgeo-org.1560.x6.nabble.com/Create-rectangle-with-minLat-maxLat-minLon-maxLon-tp5248969p5249310.html
Sent from the Quantum GIS - User mailing list archive at Nabble.com.



More information about the Qgis-user mailing list