I would like to store data into a database which is available here either as JSON or as ShapeFiles. The JSON looks something like this:

  "type": "FeatureCollection",
  "features": [
      "type": "Feature",
      "id": "HUNDEZONEOGD.12884",
      "geometry": {
        "type": "Point",
        "coordinates": [
      "geometry_name": "SHAPE",
      "properties": {
        "PARK": "Lerchenfelder Gürtel 30-32",
        "FLAECHE": "463 m²",
        "TYP": "Hundezone",
        "TELEFON": "01 4000 8042",
        "EINFRIEDUNG": "Stabilgitterzaun 1m",
        "WEBLINK1": "http://www.wien.gv.at/umwelt/parks/hundezonen.html"
"crs": {
  "type": "EPSG",
  "properties": {
    "code": "4326"
"bbox": [

I also downloaded the ShapeFiles alternative and tested different Ruby libraries to extract the information.

All of them are capable of reading the properties of the actual feature. I noticed however that they do not support reading the following fields:

  • feature.id
  • feature.type
  • feature.geometry_name
  • feature.geometry.type // supported by RGeo

Again I looked into the data using Quantum GIS and realized that the ShapeFiles do not contain the mentioned fields (feature.id, feature.type, feature.geometry_name). Does this mean these fields are not part of the ShapeFiles standard? I am confused why the publisher includes the fields in the JSON but not in the ShapeFiles.

I found out how each of the libraries accesses the attribute feature.geometry.type:

  • zhm/gdal-ruby: feature.get_geometry_ref.get_geometry_name
  • dazuma/rgeo: feature.geometry.geometry_type.to_s
  • nofxx/georuby feature.geometry.text_geometry_type

It was a bit hard to find with gdal-ruby and rgeo.


It's possible that the original source of the data is a format which has features not supported by ESRI shapefiles.

For instance, shapefiles don't support storing attribute data anywhere other than the attribute table (the "properties" section of the GeoJSON). This means the feature.id data isn't recorded in the shapefile. With a little hacking, it would be easy enough to move this information into the attribute table.

The feature.type property isn't used in shapefiles; it's specifically part of the GeoJSON structure. http://www.geojson.org/geojson-spec.html

The other properties are all recorded in the shapefile. You can access them with OGR, so I'm guessing you can do this from Ruby (I don't know the language myself).

I'm not sure if OGR lets you access the shape field name, but then it lets you retrieve a geometry object directly (using feature->GetGeometryRef()) so you shouldn't need it. http://www.gdal.org/ogr/classOGRFeature.html#acc966ce8c10ae3ddf9f14c2736fdce9a

To get the geometry type (point, polyline, polygon, etc.) use geometry->getGeometryType(). http://www.gdal.org/ogr/classOGRGeometry.html#a5c6bca18682cb933e3227552d480e1a5

As mentioned in the comments by Devdatta Tengshe, shapefiles can only store geometries of a single type (e.g. all the features are polygons). This isn't the case for GeoJSON, hence the need for a type for each feature.

  • 1
    An Important point to remember is that feature.type & feature.geometry_name are properties of the entire shapefile, and not of individual features within the shapefile. – Devdatta Tengshe Jul 17 '13 at 11:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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