[GIS] n easy way to make feature properties case insensitive

featuresgeoserveropenlayersshapefile

I have a system where a user can upload a SHP through a web form. I upload this SHP and import it to GeoServer via REST API. Later the user can interact with the data using a web client with OpenLayers.

Even though the property fields in the SHP are specified by the requirements I'm having lots of issues regarding the case sensitiveness of feature's property names. So, some of the SHP include features with a property called LENGTH, or length, or Length

I'm wondering if there's an easy way to set OpenLayers in some kind of case-insensitive mode or if should I iterate all features when importing to GeoServer to convert all properties to lowercase (or uppercase, it doesn't really matter)

Edit: Answering notkilroy's comment, the problem is that my features' properties appear as undefined if they I check them lowercased but in the shapefile are in any other case form.

/**
 * Assume the loaded SHP has all properties defined UPPERCASE in this case
 */

var Properties = {
    LENGTH: 'length',
    …
}

var featureLength = feature.getProperties()[Properties.LENGTH]; // undefined

var featureLength = feature.get(Properties.LENGTH); // undefined

Best Answer

As you suspected, running checks to make sure that uploaded files meet your standards is probably necessary. You could either automatically force a particular case, or just return a list of non-compliant fields and the rule the violate to the user to correct. You likely have more requirements beyond just the case sensitivity (like required fields) that you'll want to implement.

Alternately, you could use the feature.getProperties() method to iterate over all properties and create an additional dictionary that does the mapping from a standardized field name to the one in the shapefile, similar to what you provided in your code sample.