+ Reply to Thread
Results 1 to 15 of 15

Thread: null extent for dynamically generated polygon geometry from KMLLayer

  1. #1
    Andrew Murdoch
    Join Date
    Apr 2010
    Posts
    21
    Points
    0
    Answers Provided
    0


    0

    Default null extent for dynamically generated polygon geometry from KMLLayer

    I get this error when attempting to use the FeatureLayer selectFeatures method using a dynamically generated polygon geometry:

    In "?v=2.8 [dynamic]":
    Microsoft JScript runtime error: 'xmin' is null or not an object (Ln 48, Col 41494, Ch 41494)

    Ultimately, I want to use the actual geometry in a KML Layer to query another FeatureLayer, rather than use the Extent object of the KML geometries. I'm trying to create a new geometry object that contains all of the KML Layer geometries. There may be a better way to do this...

    When evaluating breakpoints I can tell that the code fails on this line:
    targetLayer.selectFeatures(query);

    Looking closer, I can see that the extent property is null for the new Geometry object after this line:
    geom.addRing(graphic.geometry);
    The graphic.geometry has a valid extent property (and presumably a valid geometry), but the geom object has an invalid extent after this line.

    Any thoughts or suggestions for me?

    Thanks for your help!
    Andrew




    I'm using JavaScript API v2.8

    Where kmlLayer = an esri KMLLayer object that contains a polygon for the state of Wyoming (http://dl.dropbox.com/u/2654618/kml/Wyoming.kml) and targetLayer = an esri FeatureLayer object:

    Code:
    function selectByLoadedLayer() {
     
        if (kmlLayer) {
            var geom;
    
            var layers = kmlLayer.getLayers();
            dojo.forEach(layers, function (lyr) {
                if (lyr.graphics && lyr.graphics.length > 0) {
    
                    if (lyr.declaredClass == "esri.layers.FeatureLayer") {
                        if (lyr.geometryType == "esriGeometryPoint") {
                            geom = new esri.geometry.Multipoint(map.spatialReference);
                            dojo.forEach(lyr.graphics, function (graphic) {
                                geom.addPoint(graphic.geometry);
                            });
    
                        } else if (lyr.geometryType == "esriGeometryPolygon") {
                            geom = new esri.geometry.Polygon(map.spatialReference);
                            dojo.forEach(lyr.graphics, function (graphic) {
                                geom.addRing(graphic.geometry);
                            });
    
                        } else if (lyr.geometryType == "esriGeometryPolyline") {
                            geom = new esri.geometry.PolyLine(map.spatialReference);
                            dojo.forEach(lyr.graphics, function (graphic) {
                                geom.addPath(graphic.geometry);
                            });
                        }
                    } else {
                        alert("KML layer contains a non-FeatureLayer layer object");
                    }
    
                }
    
            });
        } else {
            alert("Please load an uploaded file or a network link first.");
        }
    
        //initialize & execute query
        var query = new esri.tasks.Query();
        query.geometry = geom;
        query.returnGeometry = true;
        
        targetLayer.selectFeatures(query);
          
    }

  2. #2
    Derek Swingley

    Join Date
    May 2010
    Posts
    1,859
    Points
    892
    Answers Provided
    165


    0
    This post is marked as the answer

    Default Re: null extent for dynamically generated polygon geometry from KMLLayer

    addRing does not accept a geometry object– it expects "an array of numbers, an array of points, or a JSON object". The same goes for addPath.

    You probably want to reference your graphic.geometry's rings (for polygons) or paths (for polylines) properties. That can get tricky if you have to handle data that has holes or is multi-part. Have you thought about using the geometry service's union operation instead?
    --
    @derekswingley | ArcGIS API for JavaScript Team Member.

    If you're posting a code or html sample, please wrap it in code tags.

  3. #3
    Shuping Li
    Join Date
    May 2010
    Posts
    61
    Points
    26
    Answers Provided
    5


    0

    Default Re: null extent for dynamically generated polygon geometry from KMLLayer

    Quote Originally Posted by murdoch View Post
    Ultimately, I want to use the actual geometry in a KML Layer ...
    Why not try this:
    Code:
    if (lyr.geometryType == "esriGeometryPolygon") {
            kmlGeoms = dojo.map(lyr.graphics, function(g) {return g.geometry;});
    }

  4. #4
    Andrew Murdoch
    Join Date
    Apr 2010
    Posts
    21
    Points
    0
    Answers Provided
    0


    0

    Default Re: null extent for dynamically generated polygon geometry from KMLLayer

    Thanks for your quick reply!
    I'm now trying to use the GeometryService union method, but I'm running into this error message in the unionError handler method:
    "'geom' is undefined"
    When I look at the code in debug mode, it looks like geom is a valid array of Geometry objects...

    I'm trying to create an array of Geometry objects and that must be where I'm going wrong. Can you take a look at this code? Specifically I might be doing something wrong at this line: geom.push(graphic.geometry);

    Thanks for your help.

    Code:
    function selectByLoadedLayer() {
    
        if (kmlLayer) {
            
            var geom = new Array();
    
            var layers = kmlLayer.getLayers();
    
            dojo.forEach(layers, function (lyr) {
                if (lyr.graphics && lyr.graphics.length > 0) {
                    if (lyr.declaredClass == "esri.layers.FeatureLayer") {
                        dojo.forEach(lyr.graphics, function (graphic) {
                            geom.push(graphic.geometry);
                        });
                    }
                }
    
            });
    
          //Union Geometries in KML
          geomService.union(geom, unionComplete, unionError);
    
        } else {
            alert("Please load an uploaded file or a network link first.");
        }
    
    }
    
    function unionComplete(geometry) {
        //Initialize Query and use new union geometry
        var query = new esri.tasks.Query();
        query.geometry = geom;
        query.returnGeometry = true;
        targetLayer.selectFeatures(query);
     }
    
    function unionError(error) {
        alert(error.message);
    }

  5. #5
    Derek Swingley

    Join Date
    May 2010
    Posts
    1,859
    Points
    892
    Answers Provided
    165


    0

    Default Re: null extent for dynamically generated polygon geometry from KMLLayer

    Quote Originally Posted by Shuping View Post
    Why not try this:
    Code:
    if (lyr.geometryType == "esriGeometryPolygon") {
            kmlGeoms = dojo.map(lyr.graphics, function(g) {return g.geometry;});
    }
    That will give you an array of polygons– you'll still need some other method, like the geometry service's union operation, to create a single geometry from the array of polygons.
    --
    @derekswingley | ArcGIS API for JavaScript Team Member.

    If you're posting a code or html sample, please wrap it in code tags.

  6. #6
    Andrew Murdoch
    Join Date
    Apr 2010
    Posts
    21
    Points
    0
    Answers Provided
    0


    0

    Default Re: null extent for dynamically generated polygon geometry from KMLLayer

    My problem was a simple typo on the variable name in the unionComplete handler. The "geom" object should have been "geometry" (or vice versa).

    Code:
    function unionComplete(geometry) {
        //Initialize Query and use new union geometry
        var query = new esri.tasks.Query();
        query.geometry = geom;
        query.returnGeometry = true;
        targetLayer.selectFeatures(query);
    In order to get below the 2000 character feature layer .selectFeatures(query) limit, I had to also use the "generalize" method of the GeometryService. So I first Generalized my array of geometries and then Unioned the generalized output. Finally, I used the unioned geometry as the query geometry in selectFeatures.

    Is there a way to evaluate the geometry object as a JSON string and get the number of characters prior to running selectFeatures? If so, I could at best keep generalizing until the geometry fit that 2000 character limit, or at worst, notify the user of the problem.

    Thanks for your help,
    Andrew

  7. #7
    Andrew Murdoch
    Join Date
    Apr 2010
    Posts
    21
    Points
    0
    Answers Provided
    0


    0

    Default Re: null extent for dynamically generated polygon geometry from KMLLayer

    OK, I was able to answer one of my questions, on the length of the JSON string.

    Code:
        var geomJson = geom.toJson();
        var jsonText = JSON.stringify(geomJson);
        var jsonLength = jsonText.length;
    However, I would like to know how long the query geometry (as a JSON string length) can be. I have successfully queried with a JSON string of 2300 characters (using a proxy page to bypass the 2000 character query string limit). However, if I used the ungeneralized version of that query string, the JSON string would be 30,000 characters, which fails to select features (and fails to present any useful error or warning message).

    What is the length limit on a query's geometry JSON string object when using the FeatureLayer selectFeatures() method?

    I've done more testing and determined (at least for this install and these map services) that the max length of a query geometry object is between 4400 and 4900 characters. This was for a geometry object that was a collection of polyline objects unioned together. I'm not sure if this is based on a setting in the GeometryServer's config file? There is no error message when the query geometry object turns out to be too big. Also not sure if the query geometry object is limited strictly by the JSON length or some other measure of complexity...

    Thanks,
    Andrew
    Last edited by murdoch; 04-30-2012 at 10:51 AM. Reason: results of testing

  8. #8
    Derek Swingley

    Join Date
    May 2010
    Posts
    1,859
    Points
    892
    Answers Provided
    165


    0

    Default Re: null extent for dynamically generated polygon geometry from KMLLayer

    There isn't a limit on geometry size that can be used to query, but larger geometries require a proxy.

    Due to browser limitations (old IE), the JS API switches to using a proxy when it needs to fetch a URL longer than 2000 characters. As you've noted, you can go well past this limit when using a large geometry. The best option is to configure a proxy that runs on the same server as your web app so that you can use it to send large geometries to your service to be used in a query. See the link above for more info on setting up and configuring the proxy. Configuring a proxy is absolutely worth the time to do as the need for it will likely come up again as you develop apps with the API.

    Alternatively, if you don't need to run in old IE, you could mess around with increasing esri.config.defaults.io.postLength. But I wouldn't recommend this approach as it could have unintended side effects (and will almost certainly break your app in old versions of Internet Explorer).
    --
    @derekswingley | ArcGIS API for JavaScript Team Member.

    If you're posting a code or html sample, please wrap it in code tags.

  9. #9
    Andrew Murdoch
    Join Date
    Apr 2010
    Posts
    21
    Points
    0
    Answers Provided
    0


    0

    Default Re: null extent for dynamically generated polygon geometry from KMLLayer

    Thanks for the reply Derek.
    However I'm not sure that answers the question. I am using a proxy for large queries, but after the query geometry JSON string length exceeds about 4400 characters in length, the selectFeatures method fails to select any features.

    Even with a proxy page, (downloaded from the ESRI link), this problem occurs. Just curious what the limit for large query length might be. Or should I not be seeing this strange arbitrary limit on my end? This is using IE8, btw.

    Thanks,
    Andrew

  10. #10
    Derek Swingley

    Join Date
    May 2010
    Posts
    1,859
    Points
    892
    Answers Provided
    165


    0

    Default Re: null extent for dynamically generated polygon geometry from KMLLayer

    Is the problem only in IE8?
    --
    @derekswingley | ArcGIS API for JavaScript Team Member.

    If you're posting a code or html sample, please wrap it in code tags.

  11. #11
    Andrew Murdoch
    Join Date
    Apr 2010
    Posts
    21
    Points
    0
    Answers Provided
    0


    0

    Default Re: null extent for dynamically generated polygon geometry from KMLLayer

    This issue occurs in both IE8 and in Chrome 18. After I reach about 4400 JSON string length, the selectFeatures method stops returning any features. In Chrome, I get an error message that I don't get in IE8. The error says: "Unable to Complete Operation" from the selectFeatures error handler.

    Queries below about 4400 length seem to work fine in Chrome and in IE8.

    Andrew

  12. #12
    Derek Swingley

    Join Date
    May 2010
    Posts
    1,859
    Points
    892
    Answers Provided
    165


    0

    Default Re: null extent for dynamically generated polygon geometry from KMLLayer

    Let me take a look...I'll get back to you.
    --
    @derekswingley | ArcGIS API for JavaScript Team Member.

    If you're posting a code or html sample, please wrap it in code tags.

  13. #13
    Derek Swingley

    Join Date
    May 2010
    Posts
    1,859
    Points
    892
    Answers Provided
    165


    0

    Default Re: null extent for dynamically generated polygon geometry from KMLLayer

    Here's an example that uses a geometry that comes out to about 7300 characters (make sure you update the URL to your proxy): http://dl.dropbox.com/u/2654618/fl_s...e_geometry.txt

    That works in both Chrome and IE8 for me. Can you test that code and let us know if that works for you?

    There could be an issue with the polygon you're using...can you run your polygon through the geometry service's simplify operation and use the result of that to query your feature layer?
    --
    @derekswingley | ArcGIS API for JavaScript Team Member.

    If you're posting a code or html sample, please wrap it in code tags.

  14. #14
    Andrew Murdoch
    Join Date
    Apr 2010
    Posts
    21
    Points
    0
    Answers Provided
    0


    0

    Default Re: null extent for dynamically generated polygon geometry from KMLLayer

    I tested your polygon file and it works fine for me (through our proxy.ashx file).

    However, I've actually been testing with a KML file showing multiple polylines around Redding, CA. Maybe it is not the length that is the problem but some other measure of complexity?

    This JSON object fails (~5500 characters):

    Code:
    {"paths":[[[-13623091.7047,4952116.6667],[-13623055.6302,4952202.6571],[-13623005.3393,4952242.2741],[-13623005.7716,4952578.6665]],[[-13626762.4683,4952154.0091],[-13626787.4059,4952278.5776],[-13626915.6952,4952354.0507]],[[-13626915.6952,4952354.0507],[-13626801.5321,4952342.2127],[-13626584.8925,4952352.9089],[-13626239.1151,4952364.0777],[-13626036.1347,4952343.7974],[-13625742.7069,4952268.7129],[-13625696.9236,4952316.6434],[-13625705.8135,4952416.661],[-13625694.8656,4952642.0433]],[[-13626915.6952,4952354.0507],[-13626923.4555,4952358.6161]],[[-13622801.0314,4952553.642],[-13622765.1197,4952525.6682],[-13622537.595,4952531.6267],[-13622363.5384,4952510.9117],[-13622295.5671,4952578.8661],[-13622196.2117,4952554.3791],[-13622170.7263,4952643.2586],[-13622110.4206,4952673.6161],[-13622106.8734,4952798.1517],[-13622056.7673,4952880.4188],[-13622143.8438,4952948.513],[-13622179.0369,4953023.6609],[-13622161.0658,4953049.6801],[-13622119.286,4953054.04],[-13622027.031,4952976.3265],[-13621994.5406,4952975.6793],[-13621986.2048,4953016.0685],[-13622068.3198,4953107.3722]],[[-13622801.0314,4952553.642],[-13622892.0746,4952633.953]],[[-13622943.8065,4952563.6241],[-13622905.3931,4952601.6147],[-13622857.39,4952553.9138],[-13622801.0314,4952553.642]],[[-13623005.7716,4952578.6665],[-13622932.3513,4952546.5341],[-13622930.8112,4952514.1758],[-13622984.0156,4952499.8745]],[[-13622919.7236,4952596.1494],[-13622892.0746,4952633.953]],[[-13626299.6662,4952619.2813],[-13625757.1305,4952658.6575],[-13625728.7929,4952641.1616],[-13625694.8656,4952642.0433]],[[-13626841.3577,4952626.1773],[-13626841.1133,4952625.9892]],[[-13626841.3577,4952626.1773],[-13626835.6363,4952641.1318],[-13626820.0754,4952649.024]],[[-13626841.3577,4952626.1773],[-13626851.8404,4952598.778],[-13626919.194,4952582.7947],[-13627081.18,4952615.3534],[-13627234.3274,4952621.2911],[-13627624.098,4952734.8192],[-13627660.7249,4952757.9715],[-13627675.9033,4952808.3042]],[[-13622892.0746,4952633.953],[-13623256.2181,4952887.0805],[-13623282.4149,4953110.7174],[-13623267.4928,4953226.1779],[-13623210.4915,4953336.1933],[-13623146.2861,4953401.2073],[-13623119.6452,4953399.9155],[-13623092.7869,4953347.9621],[-13622974.853,4953306.2536],[-13622918.4554,4953230.5041],[-13622762.6091,4953173.4771],[-13622574.046,4953004.0082],[-13622471.145,4952869.3538],[-13622374.3052,4952841.6222],[-13622337.7054,4952805.1904],[-13622296.5864,4952694.1963],[-13622315.8234,4952575.3453]],[[-13625694.8656,4952642.0433],[-13625548.5686,4952645.8452],[-13625519.9542,4952688.1143],[-13625485.4221,4952695.9839],[-13625368.3416,4952649.9745],[-13625333.8332,4952663.0763],[-13625047.9101,4952651.1567],[-13624952.9877,4952587.4101],[-13624906.0636,4952597.088],[-13624814.063,4952566.5612],[-13624540.8321,4952446.6099],[-13624351.6774,4952416.3347],[-13623953.2569,4952425.3857],[-13623820.6735,4952406.0514],[-13623818.6211,4952515.1462],[-13623784.8641,4952550.665],[-13623732.7277,4952549.4774],[-13623692.5647,4952482.3145],[-13623648.1216,4952483.8618],[-13623580.5362,4952445.6444],[-13623478.6949,4952481.209],[-13623360.5824,4952452.4686],[-13623211.0475,4952468.0346],[-13623079.059,4952514.4076],[-13623063.151,4952570.313],[-13623005.7716,4952578.6665]],[[-13626820.0754,4952649.024],[-13626818.5623,4952647.9326]],[[-13626820.0754,4952649.024],[-13626782.6565,4952668.0022],[-13626689.9419,4952629.6976],[-13626631.7656,4952612.0585],[-13626299.6662,4952619.2813]],[[-13625748.0533,4952653.4665],[-13625729.0188,4952750.7748]],[[-13626243.6816,4952741.1797],[-13626299.6662,4952619.2813]],[[-13626876.4558,4952750.2055],[-13626869.1886,4952684.4505],[-13626820.0754,4952649.024]],[[-13626934.563,4952750.5866],[-13626920.9679,4952687.4568],[-13626841.3577,4952626.1773]],[[-13625707.8461,4952757.6262],[-13625690.271,4952736.6315],[-13625694.8656,4952642.0433]],[[-13628330.1969,4952765.5629],[-13628506.1301,4952767.3658],[-13628683.4227,4952831.1658],[-13628721.1656,4952832.1058],[-13628791.0334,4952907.9073],[-13628847.7526,4952930.6969],[-13628824.4002,4952854.2917],[-13628941.7555,4952772.5991],[-13629110.4324,4952730.7254],[-13629286.9521,4952792.6456],[-13629480.2658,4952866.1023],[-13629509.3119,4952906.6181],[-13629739.403,4953041.4038],[-13629948.2039,4953255.8841],[-13629962.0707,4953308.6093],[-13629998.0491,4953319.805],[-13630195.4179,4953549.158],[-13630286.8803,4953770.1635],[-13630319.5835,4953781.3377],[-13630403.8928,4953751.1667],[-13630479.2529,4953717.3473],[-13630409.839,4953490.8137],[-13630350.6416,4953379.193],[-13630109.9142,4953023.1011],[-13629910.0155,4952736.722],[-13629695.1347,4952534.977],[-13629525.1982,4952458.4565],[-13629296.8716,4952444.6433],[-13629150.5517,4952453.1355],[-13629043.4153,4952496.4957],[-13628938.2628,4952496.0504],[-13628541.4208,4952547.1949],[-13628283.7085,4952535.6395],[-13628093.2158,4952495.2792],[-13627592.0384,4952434.2024],[-13627095.8343,4952372.73],[-13626915.6952,4952354.0507]],[[-13627937.4654,4952810.6528],[-13628042.852,4952818.9864],[-13628147.4017,4952759.6782],[-13628330.1969,4952765.5629]],[[-13629028.7897,4953975.2475],[-13629088.3617,4953840.1068],[-13629089.3787,4953742.7548],[-13629062.8852,4953598.0863],[-13628941.9373,4953508.654],[-13628886.9682,4953424.1478],[-13628930.4467,4953201.3433],[-13628859.4143,4953138.072],[-13628763.8208,4953112.6599],[-13628729.0044,4953060.6912],[-13628720.0361,4952983.839],[-13628662.1492,4952954.1411],[-13628642.9296,4952913.8782],[-13628456.1382,4952790.212],[-13628330.1969,4952765.5629]]],"spatialReference":{"wkid":102100}}

    This generalized JSON object works (2394 characters):

    Code:
    {"paths":[[[-13623091.7047,4952116.6667],[-13623005.7716,4952578.6665]],[[-13626762.4683,4952154.0091],[-13626923.4555,4952358.6161]],[[-13622801.0314,4952553.642],[-13622892.0746,4952633.953]],[[-13622943.8065,4952563.6241],[-13622537.595,4952531.6267],[-13622295.5671,4952578.8661],[-13622110.4206,4952673.6161],[-13622179.0369,4953023.6609],[-13621994.5406,4952975.6793],[-13622068.3198,4953107.3722]],[[-13623005.7716,4952578.6665],[-13622984.0156,4952499.8745]],[[-13622919.7236,4952596.1494],[-13622892.0746,4952633.953]],[[-13626299.6662,4952619.2813],[-13625728.7929,4952641.1616],[-13625707.159,4952642.362]],[[-13626299.6662,4952619.2813],[-13626689.9419,4952629.6976],[-13627081.18,4952615.3534],[-13627624.098,4952734.8192],[-13627675.9033,4952808.3042]],[[-13622892.0746,4952633.953],[-13623256.2181,4952887.0805],[-13623146.2861,4953401.2073],[-13622374.3052,4952841.6222],[-13622315.8234,4952575.3453]],[[-13625707.159,4952642.362],[-13625705.8135,4952416.661],[-13625742.7069,4952268.7129],[-13626239.1151,4952364.0777],[-13626584.8925,4952352.9089],[-13627095.8343,4952372.73],[-13627592.0384,4952434.2024],[-13628093.2158,4952495.2792],[-13628541.4208,4952547.1949],[-13628938.2628,4952496.0504],[-13629296.8716,4952444.6433],[-13629695.1347,4952534.977],[-13629910.0155,4952736.722],[-13630109.9142,4953023.1011],[-13630350.6416,4953379.193],[-13630403.8928,4953751.1667],[-13630195.4179,4953549.158],[-13629948.2039,4953255.8841],[-13629739.403,4953041.4038],[-13629509.3119,4952906.6181],[-13629286.9521,4952792.6456],[-13628941.7555,4952772.5991],[-13628847.7526,4952930.6969],[-13628683.4227,4952831.1658],[-13628330.1969,4952765.5629]],[[-13625707.159,4952642.362],[-13625333.8332,4952663.0763],[-13624814.063,4952566.5612],[-13624351.6774,4952416.3347],[-13623953.2569,4952425.3857],[-13623784.8641,4952550.665],[-13623478.6949,4952481.209],[-13623005.7716,4952578.6665]],[[-13625748.0533,4952653.4665],[-13625729.0188,4952750.7748]],[[-13626243.6816,4952741.1797],[-13626299.6662,4952619.2813]],[[-13626876.4558,4952750.2055],[-13626818.5623,4952647.9326]],[[-13626934.563,4952750.5866],[-13626841.1133,4952625.9892]],[[-13625707.8461,4952757.6262],[-13625707.159,4952642.362]],[[-13627937.4654,4952810.6528],[-13628330.1969,4952765.5629]],[[-13629028.7897,4953975.2475],[-13628930.4467,4953201.3433],[-13628330.1969,4952765.5629]]],"spatialReference":{"wkid":102100}}
    Can you take a look and let me know if you have suggestions for me?
    Thanks,
    Andrew

  15. #15
    Derek Swingley

    Join Date
    May 2010
    Posts
    1,859
    Points
    892
    Answers Provided
    165


    0

    Default Re: null extent for dynamically generated polygon geometry from KMLLayer

    Here's an example using the first, larger polyline JSON you posted: http://dl.dropbox.com/u/2654618/fl_s...e_polyline.txt

    At this point, I'm not sure what to tell you. Can you open an incident with support? That, or post a link to a public page that reproduces the issue.
    --
    @derekswingley | ArcGIS API for JavaScript Team Member.

    If you're posting a code or html sample, please wrap it in code tags.

+ Reply to Thread

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts