2

The data provided to me are saved as .csv files, and are listed in this manner:

{"type":"Polygon","coordinates":[[[120.9919351,14.5451086],[120.9939584,14.545671],[120.9937922,14.5461149],[120.9941719,14.5462298],[120.9952644,14.5465698],[120.9953175,14.5463393],[120.9955468,14.5454097],[120.9955627,14.5453573],[120.9961743,14.5454329],[120.9963335,14.5448206],[120.9965709,14.5438329],[120.9968565,14.5432642],[120.9969909,14.5427672],[120.9947601,14.5422615],[120.9947116,14.5424894],[120.9943456,14.5424543],[120.9931804,14.5421634],[120.9927979,14.5420574],[120.9919351,14.5451086]]]}

I am able to use this as actual polygon layers in kepler.gl, but I am not able to use these in QGIS.

Ian Turton
  • 81,417
  • 6
  • 84
  • 185
Mike
  • 21
  • 1

1 Answers1

0
  1. Create a new, empty polygon layer in 'EPSG:4326'

  2. Create any simple polygon - we won't need it later, you can delete it afterwards.

  3. Run Geometry by expression (see also here for details) and insert the following expression (explanation at the bottom), but on line 5, instead of your_string, insert your string from your question (from { to }) and keep the single quotes ':

     geom_from_wkt( 
         'Polygon ((' ||
         regexp_replace( 
             regexp_replace( 
             'your_string',  -- replace this
             '(\\d)(,)(\\d)','\\1 \\3'),
         '.*:|\\[|\\]|}','')
     || '))')
    

The solution, here demonstrated with geometry generator: enter image description here

Explanation:

  1. Use regular expressions with regexp_replace() to replace in the input string all commas that separate digits by a space, like this 4,5 becoming 4 5.

  2. Use regular expressions with regexp_replace() to replace (delete) from the changed input string (using logical OR operator |):

    • everything up to (and including) the (first) double point : (as regex: .*:)
    • opening bracket [ (as regex: \\[, \\ is for masking the [)
    • closing bracket ] (as regex: \\])
    • closing bracket }

    Instead of

    {"type":"Polygon","coordinates":[[[120.9919351 14.5451086],[120.9939584 14.545671],...,[120.9919351 14.5451086]]]}

    you then have left only the coordinate values in an appropriate format:

    '120.9919351 14.5451086,120.9939584 14.545671,...,120.9919351 14.5451086'

  3. Add 'Polygon ((' || at the beginning and || '))' at the end with the pipe operator || to get

    'Polygon (( 120.9919351 14.5451086,120.9939584 14.545671,...,120.9919351 14.5451086 ))'

    which is the syntax you need.

  4. Convert this WKT string to a polygon using geom_from_wkt()

Babel
  • 71,072
  • 14
  • 78
  • 208