使用给定的Key:value付款人使用javascript或Jquery从JSON格式获取精确计数
我有一个Geojson,它是使用传单自动生成的使用给定的Key:value付款人使用javascript或Jquery从JSON格式获取精确计数,javascript,jquery,json,geojson,Javascript,Jquery,Json,Geojson,我有一个Geojson,它是使用传单自动生成的 var myGeometry = JSON.stringify({ "type": "FeatureCollection", "features": [ { "type": "Feature", "properties": { "id": "178", "name": "178_marker", "Fac_type": "Garbage", "C
var myGeometry = JSON.stringify({
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"id": "178",
"name": "178_marker",
"Fac_type": "Garbage",
"Comment": "",
"Photo": "IMG_20170712_122714.jpg",
"Situation": "Open",
"Duration": "5 Days",
"Composition": "Organic",
"Collection_Date": "2017-07-12",
"Remarks": ""
},
"geometry": {
"type": "Point",
"coordinates": [
87.84118652343751,
22.550610920226646
]
}
},
{
"type": "Feature",
"properties": {
"id": "131",
"name": "131_marker",
"Fac_type": "Carcass",
"Photo": "",
"Location": "Onroad",
"Situation": "Open",
"Duration": "",
"Collection_Date": "",
"Remarks": ""
},
"geometry": {
"type": "Point",
"coordinates": [
87.88787841796876,
22.872379306788158
]
}
},
{
"type": "Feature",
"properties": {
"id": "157",
"name": "157_marker",
"Fac_type": "Sewer",
"Photo": "",
"Situation": "Open",
"Matters": "Water",
"Duration": "",
"Collection_Date": "",
"Remarks": ""
},
"geometry": {
"type": "Point",
"coordinates": [
87.60498046875,
22.667244265664948
]
}
},
{
"type": "Feature",
"properties": {
"id": "187",
"name": "187_marker",
"Fac_type": "Manhole",
"Photo": "",
"Situation": "Open",
"Matters": "Water",
"Duration": "",
"Collection_Date": "",
"Remarks": ""
},
"geometry": {
"type": "Point",
"coordinates": [
87.97851562500001,
22.563293244707797
]
}
},
{
"type": "Feature",
"properties": {
"id": "212",
"name": "212_marker",
"Fac_type": "Septic_Tank",
"Photo": "",
"Situation": "Open",
"Matters": "Wastes",
"Duration": "",
"Collection_Date": "",
"Remarks": ""
},
"geometry": {
"type": "Point",
"coordinates": [
87.3468017578125,
22.715390019335942
]
}
},
{
"type": "Feature",
"properties": {
"id": "239",
"name": "239_marker",
"Fac_type": "Drains",
"Photo": "",
"Situation": "Other",
"Matters": "Other",
"Duration": "",
"Collection_Date": "",
"Remarks": ""
},
"geometry": {
"type": "Point",
"coordinates": [
87.68463134765625,
22.930571229938142
]
}
},
{
"type": "Feature",
"properties": {
"id": "264",
"name": "264_marker",
"Fac_type": "Ponds",
"Photo": "",
"Duration": "",
"Nature": "Semi_dry",
"Near_Si": "",
"Collection_Date": "2017-07-13",
"Remarks": "",
"Situation": "Dirty"
},
"geometry": {
"type": "Point",
"coordinates": [
87.43194580078125,
22.821757357861237
]
}
},
{
"type": "Feature",
"properties": {
"id": "120",
"name": "120_marker",
"Fac_type": "Ceremonial_house",
"Photo": "",
"Duration": "Night_time",
"Nature": "Loud_speaker",
"Collection_Date": "",
"Remarks": ""
},
"geometry": {
"type": "Point",
"coordinates": [
88.14880371093751,
22.705255477207526
]
}
},
{
"type": "Feature",
"properties": {
"id": "150",
"name": "150_marker",
"Data_name": "Dog House",
"Fac_type": "Animal_sheds",
"Photo": "",
"Situation": "Uncleaned",
"Duration": "5 Days",
"Nature": "Dog",
"Nearness": "Y",
"Collection_Date": "2017-07-13",
"Remarks": "444"
},
"geometry": {
"type": "Point",
"coordinates": [
88.10485839843751,
22.902743425252357
]
}
},
{
"type": "Feature",
"properties": {
"id": "260",
"name": "260_marker",
"Fac_type": "Hooking",
"Photo": "",
"Duration": "",
"Nature": "Domestic",
"Collection_Date": "",
"Remarks": ""
},
"geometry": {
"type": "Point",
"coordinates": [
88.50860595703126,
22.690052257634015
]
}
},
{
"type": "Feature",
"properties": {
"id": "285",
"name": "285_marker",
"Fac_type": "Mobile_tower",
"Photo": "",
"Location": "On_the_ground",
"Duration": "",
"Service_provider": "",
"Count": "",
"Collection_Date": "",
"Remarks": ""
},
"geometry": {
"type": "Point",
"coordinates": [
88.31909179687501,
22.844539566770546
]
}
},
{
"type": "Feature",
"properties": {
"id": "310",
"name": "310_marker",
"Fac_type": "Mela",
"Photo": "",
"Duration": "",
"Nearness": "",
"Purpose": "",
"Collection_Date": "",
"Remarks": ""
},
"geometry": {
"type": "Point",
"coordinates": [
88.31085205078126,
23.006436171834565
]
}
},
{
"type": "Feature",
"properties": {
"id": "335",
"name": "335_marker",
"Fac_type": "Urinal",
"Photo": "",
"Situation": "Potted",
"Duration": "",
"Nature": "Domestic",
"Collection_Date": "2017-07-13",
"Remarks": "",
"Nearness": "rrrrr"
},
"geometry": {
"type": "Point",
"coordinates": [
87.98950195312501,
23.01402032323799
]
}
},
{
"type": "Feature",
"properties": {
"id": "363",
"name": "363_marker",
"Fac_type": "Spitting",
"Photo": "",
"Location": "On_the_road_side",
"Situation": "Open",
"Duration": "",
"Nature": "Domestic",
"Collection_Date": "2017-07-13",
"Remarks": ""
},
"geometry": {
"type": "Point",
"coordinates": [
88.14056396484376,
23.049407390110577
]
}
},
{
"type": "Feature",
"properties": {
"id": "396",
"name": "396_marker",
"Fac_type": "Sound_Morning",
"Photo": "",
"Duration": "",
"Human": "Yes",
"Vehicle": "Bi_cycle",
"Collection_Date": "2017-07-13",
"Remarks": "",
"Magnitude_in_DB": ""
},
"geometry": {
"type": "Point",
"coordinates": [
88.50311279296876,
22.842008398595794
]
}
},
{
"type": "Feature",
"properties": {
"id": "425",
"name": "425_marker",
"Fac_type": "Sound_Noon",
"Photo": "",
"Duration": "",
"Human": "Yes",
"Vehicle": "",
"Collection_Date": "",
"Remarks": "",
"Magnitude_in_DB": ""
},
"geometry": {
"type": "Point",
"coordinates": [
87.79449462890625,
22.996323306867165
]
}
},
{
"type": "Feature",
"properties": {
"id": "450",
"name": "450_marker",
"Fac_type": "Sound_Afternoon",
"Photo": "",
"Duration": "",
"Human": "Yes",
"Vehicle": "",
"Collection_Date": "",
"Remarks": "",
"Magnitude_in_DB": ""
},
"geometry": {
"type": "Point",
"coordinates": [
87.98675537109375,
22.72805714175105
]
}
},
{
"type": "Feature",
"properties": {
"id": "475",
"name": "475_marker",
"Data_name": "Abonormal",
"Fac_type": "Odour",
"Photo": "",
"Duration": "",
"Collection_Date": "",
"Remarks": ""
},
"geometry": {
"type": "Point",
"coordinates": [
87.77252197265625,
22.72299043351299
]
}
},
{
"type": "Feature",
"properties": {
"id": "500",
"name": "500_marker",
"Fac_type": "Smoke",
"Photo": "",
"Duration": "",
"Origin": "Industrial",
"Colour": "Black",
"Collection_Date": "",
"Remarks": ""
},
"geometry": {
"type": "Point",
"coordinates": [
87.58026123046875,
22.80909892750663
]
}
},
{
"type": "Feature",
"properties": {
"id": "525",
"name": "525_marker",
"Fac_type": "Waterlogging",
"Photo": "",
"Location": "On_the_road",
"Duration": "",
"Nature": "Leakege",
"Collection_Date": "",
"Remarks": ""
},
"geometry": {
"type": "Point",
"coordinates": [
87.52258300781251,
22.98873816096074
]
}
},
{
"type": "Feature",
"properties": {
"id": "178",
"name": "178_marker",
"Fac_type": "Garbage",
"Comment": "",
"Photo": "IMG_20170712_115610.jpg",
"Situation": "Dispersed",
"Duration": "5 Days",
"Composition": "Organic",
"Collection_Date": "2017-07-12",
"Remarks": ""
},
"geometry": {
"type": "Point",
"coordinates": [
87.65716552734376,
22.497332432882345
]
}
},
{
"type": "Feature",
"properties": {
"id": "292",
"name": "292_marker",
"Fac_type": "Canal",
"Photo": "",
"Situation": "Stagnant",
"Duration": "2 Days",
"Nature": "Hydrophytic",
"Collection_Date": "2017-07-13",
"Remarks": "",
"Near_Si": "y"
},
"geometry": {
"type": "Point",
"coordinates": [
88.25042724609376,
22.525242774383898
]
}
},
{
"type": "Feature",
"properties": {
"id": "288",
"name": "288_marker",
"Fac_type": "Stream",
"Photo": "",
"Situation": "Slugged",
"Duration": "2 Days",
"Nature": "Clean",
"Nearness": "y",
"Collection_Date": "2017-07-13",
"Remarks": ""
},
"geometry": {
"type": "Point",
"coordinates": [
87.00073242187501,
22.461802035333992
]
}
},
{
"type": "Feature",
"properties": {
"id": "228",
"name": "228_marker",
"Fac_type": "Bushes",
"Photo": "",
"Location": "On_land",
"Situation": "Cleaned",
"Duration": "2 days",
"Nature": "y",
"Collection_Date": "2017-07-13",
"Remarks": ""
},
"geometry": {
"type": "Point",
"coordinates": [
87.39624023437501,
22.53285370752713
]
}
},
{
"type": "Feature",
"properties": {
"id": "197",
"name": "197_marker",
"Fac_type": "Trees",
"Photo": "",
"Location": "Other",
"Situation": "Canopy",
"Duration": "1 Day",
"Nature": "n",
"Collection_Date": "2017-07-13",
"Remarks": ""
},
"geometry": {
"type": "Point",
"coordinates": [
88.1103515625,
22.545537663981865
]
}
},
{
"type": "Feature",
"properties": {
"id": "210",
"name": "210_marker",
"Fac_type": "Excavation",
"Photo": "",
"Situation": "On_the_road",
"Duration": "1 Day",
"Nature": "Construction",
"Collection_Date": "2017-07-13",
"Remarks": ""
},
"geometry": {
"type": "Point",
"coordinates": [
87.87139892578126,
22.471954507739227
]
}
},
{
"type": "Feature",
"properties": {
"id": "243",
"name": "243_marker",
"Fac_type": "Blockage",
"Photo": "",
"Location": "On_the_ground",
"Duration": "2 Days",
"Nature": "Repair",
"Collection_Date": "2017-07-13",
"Remarks": ""
},
"geometry": {
"type": "Point",
"coordinates": [
88.0059814453125,
22.461802035333992
]
}
}
]
});
在这个geojson中,有一些属性是我预定义的,我想通过给定的“key==Value和key==Value”知道该属性的具体计数,就像我们在MySQL中做的简单查询一样
我希望使用Javascript和/或JQuery实现这一点
var count = 0;
for (var k in myGeometry) {
if (myGeometry.hasOwnProperty("'Situation': 'Open', 'Fac_type': 'Garbage'")) {
++count;
}
}
console.log(count);
请指导我如何才能使这项工作
我想使用两个值或使用Key=value的两个付款人进行查询
示例:
Total = count ("Fac_type": "Garbage","Situation": "Open")
或
答案将是2,因为在Fac_type=Garbage的位置有两个sition=Open。不要使用
JSON。如果要遍历JSON对象并使用like
片段
var myGeometry={
“类型”:“FeatureCollection”,
“特点”:[{
“类型”:“功能”,
“财产”:{
“id”:“178”,
“名称”:“178_标记”,
“Fac_类型”:“垃圾”,
“评论”:“评论”,
“照片”:“IMG_20170712_122714.jpg”,
“情境”:“开放”,
“持续时间”:“5天”,
“成分”:“有机”,
“收款日期”:“2017-07-12”,
“备注”:”
},
“几何学”:{
“类型”:“点”,
“坐标”:[
87.84118652343751,
22.550610920226646
]
}
},
{
“类型”:“功能”,
“财产”:{
“id”:“131”,
“名称”:“131_标记”,
“Fac_类型”:“胴体”,
“照片”:“,
“位置”:“Onroad”,
“情境”:“开放”,
“期间”:“期间”,
“收款日期”:“,
“备注”:”
},
“几何学”:{
“类型”:“点”,
“坐标”:[
87.88787841796876,
22.872379306788158
]
}
},
{
“类型”:“功能”,
“财产”:{
“id”:“157”,
“名称”:“157_标记”,
“Fac_类型”:“下水道”,
“照片”:“,
“情境”:“开放”,
“事项”:“水”,
“期间”:“期间”,
“收款日期”:“,
“备注”:”
},
“几何学”:{
“类型”:“点”,
“坐标”:[
87.60498046875,
22.667244265664948
]
}
},
{
“类型”:“功能”,
“财产”:{
“id”:“187”,
“名称”:“187_标记”,
“Fac_类型”:“人孔”,
“照片”:“,
“情境”:“开放”,
“事项”:“水”,
“期间”:“期间”,
“收款日期”:“,
“备注”:”
},
“几何学”:{
“类型”:“点”,
“坐标”:[
87.97851562500001,
22.563293244707797
]
}
},
{
“类型”:“功能”,
“财产”:{
“id”:“212”,
“名称”:“212_标记”,
“Fac_型”:“化粪池”,
“照片”:“,
“情境”:“开放”,
“事项”:“废物”,
“期间”:“期间”,
“收款日期”:“,
“备注”:”
},
“几何学”:{
“类型”:“点”,
“坐标”:[
87.3468017578125,
22.715390019335942
]
}
},
{
“类型”:“功能”,
“财产”:{
“id”:“239”,
“名称”:“239_标记”,
“Fac_类型”:“排水管”,
“照片”:“,
“情况”:“其他”,
“事项”:“其他”,
“期间”:“期间”,
“收款日期”:“,
“备注”:”
},
“几何学”:{
“类型”:“点”,
“坐标”:[
87.68463134765625,
22.930571229938142
]
}
},
{
“类型”:“功能”,
“财产”:{
“id”:“264”,
“名称”:“264_标记”,
“Fac_类型”:“池塘”,
“照片”:“,
“期间”:“期间”,
“自然”:“半干”,
“近西”:“,
“收款日期”:“2017-07-13”,
“备注”:“,
“情境”:“肮脏”
},
“几何学”:{
“类型”:“点”,
“坐标”:[
87.43194580078125,
22.821757357861237
]
}
},
{
“类型”:“功能”,
“财产”:{
“id”:“120”,
“名称”:“120_标记”,
“Fac_类型”:“礼仪之家”,
“照片”:“,
“持续时间”:“夜间时间”,
“自然”:“扬声器”,
“收款日期”:“,
“备注”:”
},
“几何学”:{
“类型”:“点”,
“坐标”:[
88.14880371093751,
22.705255477207526
]
}
},
{
“类型”:“功能”,
“财产”:{
“id”:“150”,
“名称”:“150_标记”,
“数据名称”:“狗屋”,
“工厂类型”:“动物棚”,
“照片”:“,
“情况”:“未清洗”,
“持续时间”:“5天”,
“自然”:“狗”,
“接近度”:“Y”,
“收款日期”:“2017-07-13”,
“备注”:“444”
},
“几何学”:{
“类型”:“点”,
“坐标”:[
88.10485839843751,
22.902743425252357
]
}
},
{
“类型”:“功能”,
“财产”:{
“id”:“260”,
“名称”:“260_标记”,
“Fac_类型”:“挂钩”,
“照片”:“,
“期间”:“期间”,
“自然”:“家庭”,
“收款日期”:“,
“备注”:”
},
“几何学”:{
“类型”:“点”,
“坐标”:[
88.50860595703126,
22.690052257634015
]
}
},
{
“类型”:“功能”,
“财产”:{
“id”:“285”,
“名称”:“285_标记”,
“Fac_类型”:“移动_塔”,
“照片”:“,
“地点”:“在地面上”,
“期间”:“期间”,
“服务提供方”:“,
“计数”:“,
“收款日期”:“,
“备注”:”
},
“几何学”:{
“类型”:“点”,
“坐标”:[
88.31909179687501,
22.84453
count ("Garbage" and "Open")
var count = 0;
$.each(myGeometry.features, function(k, v) {
var p = v.properties || null;
if (p.hasOwnProperty("Situation") && p.Situation == 'Open' && p.hasOwnProperty("Fac_type") && p.Fac_type == 'Garbage') {
++count;
}
});