0

I have a string of properly formatted JSON from a VB.NET function that I am trying to pass to JavaScript where I can convert it into an OpenLayers vector layer. The string can be variable length, sometimes as small as 5,000 characters and sometimes as long as 40,000,000 characters.

Here is a small example of the JSON:

"{"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"MultiPolygon","coordinates":[[[[-79.546437887619277,41.450810394091974],[-79.546373336415854,41.450878338383419],[-79.546186240728744,41.450930517576978],[-79.546030161587709,41.451004424821683],[-79.546437887619277,41.450810394091974]]]]},"properties":{"tract":11001180000000,"stand_num":"11001180000006","acres":0.585540920000}},.....etc.

If the string is less than 100,000 characters I can successfully send it to my JavaScript function as a normal string variable OR as a serialized variable, can successfully read it as GeoJSON, and add the features to my OpenLayers map using the normal OpenLayers GeoJSON methods. The following JavaScript takes the VB.NET serialized string and adds it to the map;

            var geojson_format = new OpenLayers.Format.GeoJSON(); 
            var vector_layer = new OpenLayers.Layer.Vector("query_POSTGIS");
            var parsedJSON = JSON.parse(outputStr);
            alert(geojson_format.isValidType(parsedJSON, "FeatureCollection")); 

            var geoJsonStr = geojson_format.read(parsedJSON, "FeatureCollection"); 
            vector_layer.addFeatures(geoJsonStr); 

This code works great until I get to the 100,000 character limit. Any suggestions on how to make this work with strings over 100,000 characters?

  • Does it fail server-side or client side? If it's server-side, I recall there being some sort of setting to change the maximum length of the json response. Other thought: isn't that a lot of data to be shoving into a vector layer? Could you simplify the polygons / use a WMS layer then only send over the features a user wants to work with or otherwise change the workflow? – mlinth Nov 20 '15 at 14:21
  • The fail appears to be on the client side but I'm not sure. It's really not a lot of vector data though. The 20,000,000 character files are only about 2,500 polygons. The vectors are served dynamically based on user queries and the geo data is joined to other tables of data that constantly change so there is no way to prepare a WMS in my GeoServer for each potential query. – Todd Krueger Nov 20 '15 at 14:35
  • This seems like it should be something simple and painfully obvious because this is exactly what PostGres/PostGIS is supposed to do, serve query-able geographic data. But I can't seem to figure out what is wrong. :-( – Todd Krueger Nov 20 '15 at 14:39
  • Try using st_simplify. That should significantly reduce the number of characters returned, although probably not sufficiently for your largest queries. I don't think the limitation is postgis - it's doing exactly what you ask. But I'd suggest you find the root cause of the problem. Is the server sending what you expect, or is OpenLayers falling over? Any error messages? – mlinth Nov 20 '15 at 14:51
  • st_simplify didn't solve this particular problem but I will definitely be using that command in other places!! Here is the error from the Google Chrome console --- "throw Sys.Net.WebServiceProxy._createFailedError(methodName, String.format(Sys.Res.webServiceFailed, methodName, error));" – Todd Krueger Nov 20 '15 at 15:02
0

I was able to solve the issue. It appears that in .NET there is a limit to how long a string that is serialized can be and you must explicitly declare a maxJsonLength in your Web.config. I was able to solve the problem by adding the following to my Web.config:

 <system.web.extensions>
        <scripting>
            <webServices>
                <jsonSerialization maxJsonLength="50000000"/>
            </webServices>
        </scripting>
    </system.web.extensions>

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.