Skip to main content
naming
Source Link
Vince
  • 20.3k
  • 16
  • 48
  • 65

Inserting GeoJSON in PostgresPostgreSQL using laravel controller

Actually.. I have GeoJsonGeoJSON that I send from javascript into controller. My GeoJSON:

Inserting GeoJSON in Postgres using laravel controller

Actually.. I have GeoJson that I send from javascript into controller. My GeoJSON:

Inserting GeoJSON in PostgreSQL using laravel controller

Actually.. I have GeoJSON that I send from javascript into controller. My GeoJSON:

edited tags
Link
Ian Turton
  • 83.2k
  • 6
  • 89
  • 189
Title changed, Content structured
Source Link
Taras
  • 34.1k
  • 4
  • 73
  • 148

Insert GeoJson Inserting GeoJSON in Postgres using laravel controller

Actually.. I have GeoJson that I send from javascript into controller..My GeoJson My GeoJSON:

{
    "type": "FeatureCollection",
    "features": [{
        "type": "Feature",
        "geometry": {
            "type": "Point",
            "coordinates": [101.21719328770531, 3.113987284801912]
        },
        "properties": null
    }, {
        "type": "Feature",
        "geometry": {
            "type": "LineString",
            "coordinates": [
                [101.18330230120145, 3.046205311794175],
                [101.13585492009604, 2.985201536087212],
                [101.19008049850223, 2.9174195630794753]
            ]
        },
        "properties": null
    }]
}
{
    "type": "FeatureCollection",
    "features": [{
        "type": "Feature",
        "geometry": {
            "type": "Point",
            "coordinates": [101.21719328770531, 3.113987284801912]
        },
        "properties": null
    }, {
        "type": "Feature",
        "geometry": {
            "type": "LineString",
            "coordinates": [
                [101.18330230120145, 3.046205311794175],
                [101.13585492009604, 2.985201536087212],
                [101.19008049850223, 2.9174195630794753]
            ]
        },
        "properties": null
    }]
}

and then I found this single heterogeneous GEOMETRYCOLLECTIONGEOMETRYCOLLECTION from this link

So, My sqlSQL something like this:

    SELECT public.ST_SetSRID(public.ST_Collect(public.ST_GeomFromGeoJSON(feat->>'geometry')), 4326) as geom
    FROM (
      SELECT json_array_elements('{
                      "type":"FeatureCollection",
                      "features":[{
                                 "type":"Feature",
                                 "geometry":{
                                            "type":"Point",
                                            "coordinates":[101.21719328770531,3.113987284801912]
                                  },
                                 "properties":null
                      },{
                      "type":"Feature",
                             "geometry":{
                                        "type":"LineString",
                                        "coordinates":[[101.18330230120145,3.046205311794175],
                                                       [101.13585492009604,2.985201536087212],
                                                       [101.19008049850223,2.9174195630794753]
                                                      ]
                                        },
                             "properties":null
                      }]
                     }'::json->'features') AS feat) AS f;
SELECT public.ST_SetSRID(public.ST_Collect(public.ST_GeomFromGeoJSON(feat->>'geometry')), 4326) as geom
FROM (
      SELECT json_array_elements('{
                      "type":"FeatureCollection",
                      "features":[{
                                 "type":"Feature",
                                 "geometry":{
                                            "type":"Point",
                                            "coordinates":[101.21719328770531,3.113987284801912]
                                  },
                                 "properties":null
                      },{
                      "type":"Feature",
                             "geometry":{
                                        "type":"LineString",
                                        "coordinates":[[101.18330230120145,3.046205311794175],
                                                       [101.13585492009604,2.985201536087212],
                                                       [101.19008049850223,2.9174195630794753]
                                                      ]
                                        },
                             "properties":null
                      }]
                     }'::json->'features') AS feat
) AS f;

It can run it ..but. but, how can I insert this into my column geom in my table by using something like this 'geom' => db::raw("from my sql")'geom' => db::raw("from my sql")?

Insert GeoJson in Postgres using laravel controller

Actually.. I have GeoJson that I send from javascript into controller..My GeoJson:

{
    "type": "FeatureCollection",
    "features": [{
        "type": "Feature",
        "geometry": {
            "type": "Point",
            "coordinates": [101.21719328770531, 3.113987284801912]
        },
        "properties": null
    }, {
        "type": "Feature",
        "geometry": {
            "type": "LineString",
            "coordinates": [
                [101.18330230120145, 3.046205311794175],
                [101.13585492009604, 2.985201536087212],
                [101.19008049850223, 2.9174195630794753]
            ]
        },
        "properties": null
    }]
}

and then I found this single heterogeneous GEOMETRYCOLLECTION from this link

So, My sql something like this:

    SELECT public.ST_SetSRID(public.ST_Collect(public.ST_GeomFromGeoJSON(feat->>'geometry')), 4326) as geom
    FROM (
      SELECT json_array_elements('{
                      "type":"FeatureCollection",
                      "features":[{
                                 "type":"Feature",
                                 "geometry":{
                                            "type":"Point",
                                            "coordinates":[101.21719328770531,3.113987284801912]
                                  },
                                 "properties":null
                      },{
                      "type":"Feature",
                             "geometry":{
                                        "type":"LineString",
                                        "coordinates":[[101.18330230120145,3.046205311794175],
                                                       [101.13585492009604,2.985201536087212],
                                                       [101.19008049850223,2.9174195630794753]
                                                      ]
                                        },
                             "properties":null
                      }]
                     }'::json->'features') AS feat) AS f;

It can run..but, how can I insert this into my column geom in my table by using something like this 'geom' => db::raw("from my sql")

Inserting GeoJSON in Postgres using laravel controller

Actually.. I have GeoJson that I send from javascript into controller. My GeoJSON:

{
    "type": "FeatureCollection",
    "features": [{
        "type": "Feature",
        "geometry": {
            "type": "Point",
            "coordinates": [101.21719328770531, 3.113987284801912]
        },
        "properties": null
    }, {
        "type": "Feature",
        "geometry": {
            "type": "LineString",
            "coordinates": [
                [101.18330230120145, 3.046205311794175],
                [101.13585492009604, 2.985201536087212],
                [101.19008049850223, 2.9174195630794753]
            ]
        },
        "properties": null
    }]
}

and then I found this single heterogeneous GEOMETRYCOLLECTION from this link

So, My SQL something like this:

SELECT public.ST_SetSRID(public.ST_Collect(public.ST_GeomFromGeoJSON(feat->>'geometry')), 4326) as geom
FROM (
      SELECT json_array_elements('{
                      "type":"FeatureCollection",
                      "features":[{
                                 "type":"Feature",
                                 "geometry":{
                                            "type":"Point",
                                            "coordinates":[101.21719328770531,3.113987284801912]
                                  },
                                 "properties":null
                      },{
                      "type":"Feature",
                             "geometry":{
                                        "type":"LineString",
                                        "coordinates":[[101.18330230120145,3.046205311794175],
                                                       [101.13585492009604,2.985201536087212],
                                                       [101.19008049850223,2.9174195630794753]
                                                      ]
                                        },
                             "properties":null
                      }]
                     }'::json->'features') AS feat
) AS f;

It can run it ... but, how can I insert this into my column geom in my table by using something like this 'geom' => db::raw("from my sql")?

Source Link
Loading