Formatting GeoJSON for Foundry: Validating and Ingesting Shapely Geometries

What data does the GeoJSON column need to be in to be valid in Foundry?

I am working with a Shapely Geometry object in Python and trying to format it as GeoJSON for ingestion into Palantir Foundry. Here’s an example of my object:

'MULTIPOLYGON (((-1.2247022322882 54.626110158762, -1.22492912271903 54.625989867433, -1.2249211633629 54.6260001134914, -1.22488322574379 54.626040310999, -1.22482506925512 54.6260848724911, -1.22477336368236 54.6261159951613, -1.22471090232615 54.6261425556268, -1.22464854336016 54.6261637246872, -1.22461123725777 54.6261706753108, -1.22457090200732 54.6261740118505, -1.22453690359728 54.6261727733594, -1.22466779717883 54.6261279064389, -1.2247022322882 54.626110158762)), ((-1.19570203413836 54.6873598813336, -1.19572299057562 54.6873591213825, -1.19574391152509 54.6873601586105, -1.19575009783907 54.6873610982787, -1.195767872404 54.6873643614428, -1.19578406934326 54.6873689622225, -1.19579868865786 54.6873749006187, -1.19581251472721 54.6873817324704, -1.19582476317317 54.6873899019394, -1.19583240293052 54.6873957941243, -1.19583996285377 54.6874057299701, -1.19584519625596 54.6874156504135, -1.19584886090257 54.6874264591802, -1.19585019902511 54.6874372525449, -1.19585076163947 54.6874480407757, -1.1958513153835 54.6874592783021, -1.19584873160808 54.6874722924755, -1.1958430103098 54.6874870832958, -1.19583961553702 54.6875018895177, -1.1958395268296 54.6875063824747, -1.19584075850327 54.6875225673877, -1.1958435411991 54.6875387625686, -1.19584574354134 54.6875450681102, -1.19585151296663 54.6875671246708, -1.19586039331496 54.6875887524708, -1.19587238459107 54.6876099515097, -1.19587693121862 54.6876153738607, -1.1958905444979 54.6876329887998, -1.19590651093745 54.6876492712509, -1.19592481279881 54.6876651198047, -1.19594468344049 54.6876800800309, -1.1959668983765 54.6876941570621, -1.19614650236566 54.6877506163337, -1.19615268874885 54.6877515559813, -1.19616581042926 54.6877547882947, -1.19617812999572 54.6877593633618, -1.19618888080108 30713001605, -1.24077427521141 54.7230687592283, -1.24076606339264 ... )))'

I have written it to a GeoJSON object using the following code:

df["geojson"] = df["geometry"].apply(lambda geom: geom.__geo_interface__)

This results in the following GeoJSON object:

{

  "type": "MultiPolygon",

  "coordinates": [

    [

      [

        (-1.2247022322882, 54.626110158762),

        (-1.22492912271903, 54.625989867433),

        (-1.2249211633629, 54.6260001134914),

        (-1.22488322574379, 54.626040310999),

        (-1.22482506925512, 54.6260848724911),

        (-1.22477336368236, 54.6261159951613),

        (-1.22471090232615, 54.6261425556268),

        (-1.22464854336016, 54.6261637246872),

        (-1.22461123725777, 54.6261706753108),

        (-1.22457090200732, 54.6261740118505),

        (-1.22453690359728, 54.6261727733594),

        (-1.22466779717883, 54.6261279064389),

        (-1.2247022322882, 54.626110158762)

      ]

    ],

    ...

  ]

}

Questions:

  1. Is this format valid for Foundry to read and display these shapes on a map?

  2. If not, what adjustments should I make to ensure Foundry accepts and renders these geometries correctly?

Additional Notes:

• The geo_interface is the standard for GeoJSON, but Foundry may require additional properties or a specific structure to parse the data correctly.

• Any examples or best practices for handling multi-geometries like MultiPolygon in Foundry would be greatly appreciated.

Hey,

I believe MultiPolygons are supported.

Have you had a look at this transform in pipeline builder? It may be helpful for working with GeoJSON and the ontology.

-Eirik

1 Like

Thankyou @eiriklt

The transform you mentioned was super handy but I couldn’t get it to play nicely with my csv geojson object.

My workflow was:

  1. load in shapefile to geopandas.GeoDataFrame
  2. Export the GeoDataFrame geometry column to a json string:
    # Convert geometry to GeoJSON format
    df["geojson"] = df["geometry"].apply(lambda geom: geom.__geo_interface__)

    # Export GeoJSON as JSON Strings for CSV
    df["geojson"] = df["geojson"].apply(json.dumps)
  1. Upload that csv to Foundry

This was a handy tool just to sense check the json was valid before uploading into Foundry:
https://geojsonlint.com/

This was a super useful function in Python to also sense check the object:

from shapely.validation import explain_validity

Hi,

I had a lot of problems like this in the past, some of the things I did to fix it:

1. GeoJSON Format: Ensure that the coordinates follow the longitude, latitude order, which your example seems to do.
2. Adding properties: Foundry often expects a properties field for each geometry. This can be an empty object ("properties": {}) or populated with metadata related to the geometry. For example:

{
  "type": "MultiPolygon",
  "coordinates": [
    [[...]]
  ],
  "properties": {}
}
  1. Coordinate Precision: Some systems may be sensitive to the precision of the coordinates. You may want to reduce the precision slightly (e.g., rounding to a few decimal places) if Foundry has performance issues with highly precise data. I had this sometimes, but maybe it was just a bug that they fixed.
1 Like