簡體   English   中英

引用geoJSON文件中的數據

[英]Referencing data in a geoJSON file

JS新手。 該語句似乎不起作用:

if (kcdfp_parcel[i].InActive == 0)

數據是一個帶有變量“ kcdfp_parcel”的geoJSON文件。

這是文件的一部分:

kcdfp_parcel = [{“ type”:“ FeatureCollection”,“ crs”:{“ type”:“ name”,“ properties”:{“ name”:“ urn:ogc:def:crs:OGC:1.3:CRS84”} },

"features": [
{ "type": "Feature", "properties": { "MAJOR": "000440", "MINOR": "0018", "PIN": "0004400018", "FarmID": 3101.000000, "LastName": "Codiga", "Acres": 62.940000, "Cooperativ": null, "InActive": 0, "ParcelNumb": "0004400018", "Shape_Leng": 0.024319, "Shape_Area": 0.000030 }, "geometry": { "type": "Polygon", "coordinates": [ [ [ -122.254601971999989,

我是否正確引用了LastName字段(例如,我是否需要使用kcdfp_parcel.features.InActive)?

還是我的IF陳述錯誤?

應該能夠通過kcdfp_parcel.features[some_index].properties.InActive引用“ InActive”,如以下示例所示。 通過console.log在瀏覽器控制台上的輸出如下所示:

特征索引0的屬性InActive為0,ParcelNumb為0004400018
要素索引1的屬性InActive為0,ParcelNumb為0006400009

<!DOCTYPE html>
<html>
    <meta charset="UTF-8">
    <body>
        <h1>Check your browser console...</h1>
    </body>
    <script type="text/javascript">
        var kcdfp_parcel = { 
            "type": "FeatureCollection", 
            "crs": { 
                "type": "name", 
                "properties": { 
                   "name": "…" 
                } 
            }, 
            "features": [ 
                { 
                    "type": "Feature", 
                    "properties": { 
                        "InActive": 0, 
                        "ParcelNumb": "0004400018" 
                    }, 
                    "geometry": { 
                        "type": "Polygon", 
                        "coordinates": [ [ [ -122.254601971999989, 47.364317413000038 ], [ -122.254231611999955, 47.364320569000029 ] ] ] 
                    } 
                }, 
                { 
                    "type": "Feature", 
                    "properties": { 
                        "InActive": 0, 
                        "ParcelNumb": "0006400009" 
                    }, 
                    "geometry": { 
                       "type": "MultiPolygon", 
                       "coordinates": [ [ [ -122.059132819999945, 47.197189012000081 ], [ -122.059119953999982, 47.197182407000071 ] ] ] 
                    } 
                } 
            ]
        };

        for (var i = 0; i < kcdfp_parcel.features.length; i++) {
            console.log("Features index " + i + " has property InActive of " + kcdfp_parcel.features[i].properties.InActive + 
                        " and ParcelNumb of " + kcdfp_parcel.features[i].properties.ParcelNumb);
        }
    </script>
</html>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM