koopjs / FeatureServer

An open source Geoservices Implementation (deprecated)
https://geoservices.github.io
Other
101 stars 32 forks source link

Support conversion of ISO 8601 dates to esriFieldTypeDate #16

Closed jkerr5 closed 7 years ago

jkerr5 commented 7 years ago

The feature server currently recognizes strings that are formatted as ISO 8601 date formats in provider features as esriFieldTypeDate. The values for these fields should actually be milliseconds since epoch (January 1, 1970) in UTC though so they need to be converted in the response.

This creates a defined contract between the FeatureServer and koop providers that says that all date fields returned by a provider must be in ISO 8601 formatted strings and that the FeatureServer will convert those to milliseconds since epoch in UTC.

dmfenton commented 7 years ago

This is a tricky one, but I expect to have a solution by the end of the week.

dmfenton commented 7 years ago

Resolved @v2.3.1

This will detect dateFields if the first feature has a field with an ISO string. Otherwise you can pass in a field object in the metadata like so:

{
  type: 'FeatureCollection',
  features: [],
  metadata: {
    fields: [
      {
        name: 'SomeDateField',
        type: 'Date'
      },
      {
        name: 'SomeDoubleField',
        type: 'Double'
      },
      {
        name: 'SomeIntegerField',
        type: 'Integer'
      },
      {
        name: 'SomeStringField',
        type: 'String'
      }
    ]
  }
}
jkerr5 commented 7 years ago

It looks like it is converting the date fields correctly but the fields section is now listing the data type for those fields as esrifieldTypeInteger. Below is an example of a query result.

Also note that the OBJECTID field is not in the result attributes as it should be.

{
  "objectIdFieldName": "OBJECTID",
  "globalIdFieldName": "",
  "hasZ": false,
  "hasM": false,
  "spatialReference": {
    "wkid": 4326
  },
  "fields": [
    {
      "name": "OBJECTID",
      "type": "esrifieldTypeInteger",
      "alias": "OBJECTID",
      "length": null,
      "editable": false,
      "nullable": true,
      "domain": null
    },
    {
      "name": "urlpubtimedate",
      "type": "esrifieldTypeInteger",
      "alias": "urlpubtimedate",
      "length": null,
      "editable": false,
      "nullable": true,
      "domain": null
    },
    {
      "name": "url",
      "type": "esriFieldTypeString",
      "alias": "url",
      "length": null,
      "editable": false,
      "nullable": true,
      "domain": null
    },
    {
      "name": "name",
      "type": "esriFieldTypeString",
      "alias": "name",
      "length": null,
      "editable": false,
      "nullable": true,
      "domain": null
    },
    {
      "name": "urltone",
      "type": "esriFieldTypeDouble",
      "alias": "urltone",
      "length": null,
      "editable": false,
      "nullable": true,
      "domain": null
    },
    {
      "name": "domain",
      "type": "esriFieldTypeString",
      "alias": "domain",
      "length": null,
      "editable": false,
      "nullable": true,
      "domain": null
    },
    {
      "name": "urllangcode",
      "type": "esriFieldTypeString",
      "alias": "urllangcode",
      "length": null,
      "editable": false,
      "nullable": true,
      "domain": null
    },
    {
      "name": "geores",
      "type": "esrifieldTypeInteger",
      "alias": "geores",
      "length": null,
      "editable": false,
      "nullable": true,
      "domain": null
    }
  ],
  "features": [
    {
      "type": "Feature",
      "attributes": {
        "urlpubtimedate": 1495625400000,
        "url": "http:\/\/www.mathrubhumi.com\/news\/india\/pakistan-fighter-jets-fly-close-to-siachen-glacier--1.1961754",
        "name": "Pakistan",
        "urltone": 3.08,
        "domain": "mathrubhumi.com",
        "urllangcode": "mal",
        "geores": 1
      }
    }
  ]
}
dmfenton commented 7 years ago

Would you please provide a same of your input feature collection, including metadata?

jkerr5 commented 7 years ago

I added the the metadata.fields array with the field types as specified and it works better. The issue seems to be when there is no metadata.fields so it is inspecting the first feature for the types. I'll have to revert my changes to generate a response with the prototype feature instead of the metadata.fields.

A side note on this is that the esrifieldTypeInteger has the incorrect case so Insights throws an error. It looks like you missed a capital "F" in camel casing that value in field-map.js.

dmfenton commented 7 years ago

Can you provide the first feature so I can add it as a test fixture please?

jkerr5 commented 7 years ago

Sorry, I had to switch back to a prior version to try and reproduce. I must have had something messed up on my side as I can't reproduce the problem now. It appears to be ok other than the esrifieldTypeInteger typo (see below).

{
  "objectIdFieldName": "OBJECTID",
  "globalIdFieldName": "",
  "hasZ": false,
  "hasM": false,
  "spatialReference": {
    "wkid": 4326
  },
  "fields": [
    {
      "name": "OBJECTID",
      "type": "esrifieldTypeInteger",
      "alias": "OBJECTID",
      "length": null,
      "editable": false,
      "nullable": true,
      "domain": null
    },
    {
      "name": "urlpubtimedate",
      "type": "esriFieldTypeDate",
      "alias": "urlpubtimedate",
      "length": null,
      "editable": false,
      "nullable": true,
      "domain": null
    },
    {
      "name": "url",
      "type": "esriFieldTypeString",
      "alias": "url",
      "length": null,
      "editable": false,
      "nullable": true,
      "domain": null
    },
    {
      "name": "name",
      "type": "esriFieldTypeString",
      "alias": "name",
      "length": null,
      "editable": false,
      "nullable": true,
      "domain": null
    },
    {
      "name": "urltone",
      "type": "esriFieldTypeDouble",
      "alias": "urltone",
      "length": null,
      "editable": false,
      "nullable": true,
      "domain": null
    },
    {
      "name": "domain",
      "type": "esriFieldTypeString",
      "alias": "domain",
      "length": null,
      "editable": false,
      "nullable": true,
      "domain": null
    },
    {
      "name": "urllangcode",
      "type": "esriFieldTypeString",
      "alias": "urllangcode",
      "length": null,
      "editable": false,
      "nullable": true,
      "domain": null
    },
    {
      "name": "geores",
      "type": "esriFieldTypeInteger",
      "alias": "geores",
      "length": null,
      "editable": false,
      "nullable": true,
      "domain": null
    }
  ],
  "features": [
    {
      "type": "Feature",
      "attributes": {
        "urlpubtimedate": 1495625400000,
        "url": "http:\/\/gordonua.com\/news\/war\/gruppa-doneckih-boevikov-propala-po-puti-na-peredovye-pozicii-razvedka-189711.html",
        "name": "Georgia, United States",
        "urltone": -3.7,
        "domain": "gordonua.com",
        "urllangcode": "rus",
        "geores": 2
      }
    }
  ]
}
dmfenton commented 7 years ago

Integer field typo is fixed as of 2.3.2