3

How can I make a shapefile (Geometry/polygon) using this coordinate point information?

MultiPolygon (((4600000 3500000, 4600000 3600000, 4700000 3600000, 4700000 3500000, 4600000 3500000)))

CRS = EPSG:3035

I have tried to create shapefile as virtual layer after add from excel into QGIS. I have used the code

select MakePolygon(
    GeomFromText(concat('LINESTRING(',
                "left", ' ', "top",
                ',',
                "left", ' ', "bottom",
                ',',
                "right", ' ', "bottom",
                ',',
                "right", ' ', "top",
                ',',
                "left", ' ', "top",
                ')'))
                ) as geometry, *
From 100km_ploygon_input_03.02_CSV

1

It does not work and give error.

enter image description here

3
  • what error does it give?
    – Ian Turton
    Sep 29, 2022 at 13:37
  • Query execution error on CREATE TEMP VIEW _tview AS select MakePolygon( GeomFromText(concat('LINESTRING(', "left", ' ', "top", ',', "left", ' ', "bottom", ',', "right", ' ', "bottom", ',', "right", ' ', "top", ',', "left", ' ', "top", ')')) ) as geometry, * From grid_1m_1m_v3.01: 1 - near ".01": syntax error
    – Hasan
    Sep 29, 2022 at 13:46
  • 2
    From grid_1m_1m_v3.01 must be double quoted (From "grid_1m_1m_v3.01")
    – Mayo
    Sep 29, 2022 at 13:55

1 Answer 1

4

You dont need to specify what coordinate represents which location and not that it is a Polygon because your datasource is already provided as WKT where these are specified. Try this query:

Select ST_SetSRID(ST_GeomFromText('MultiPolygon (((4600000 3500000, 4600000 3600000, 4700000 3600000, 4700000 3500000, 4600000 3500000)))'),3035)

Then save the virtual layer as Shapefile. (A virtual layer is not a Shapefile; a Shapefile is one of many file formats to store geographic informations, btw old with many disadvantages over other formats)

4
  • Doesn't import delimited text have an option to specify that the geometries are in WKT?
    – Ian Turton
    Sep 29, 2022 at 14:46
  • 1
    Yes import from delimited text has this option, but import from Excel can only add x/y geometry. So saving the Excel as CSV would probably the best solution.
    – MrXsquared
    Sep 29, 2022 at 14:50
  • @MrXsquared Thanks, certainly virtual layer is not shapefile, have to save shapefile at the end. However, I have tried your given code, unfortunately, it did not work. It gave error Query preparation error on PRAGMA table_info(_tview): no such function: ST_SetSRID
    – Hasan
    Sep 30, 2022 at 7:36
  • Ok, seems like that function is not available. Thats really suprising. I dont have QGIS by hand atm, but I think there is a field or button below the query field where you can set the CRS. Just set your CRS there, or if there is no field, set it after you have created the virtual layer via layer properties. Just use the query without ST_SetSRID as this: Select ST_GeomFromText('MultiPolygon (((4600000 3500000, 4600000 3600000, 4700000 3600000, 4700000 3500000, 4600000 3500000)))').
    – MrXsquared
    Sep 30, 2022 at 7:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.