以arcgis 提供的地图服务为例 http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer
var result = {
displayFieldName: "STATE_NAME",
features: [……],
fieldAliases: {……},
fields: [],
geometryType: "esriGeometryPolygon",
spatialReference: {
wkid: 4269
}
“where”: “1=1”,
var url = "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer"
url += "/" + "5"+ "/query"; // states 查询
var params = {
"f": "json",
"where": "1=1",
"returnGeometry": "true",
"outFields": "*"
};
$.ajax({
url:url,
type:'post',
data:params,
dataType: "json",
success: function(data){
console.log(data);
//var features = new ol.format.EsriJSON().readFeatures(data);
//console.log(features);
}
})
参考:在 ArcGIS 中使用的查询表达式的 SQL 参考
// 坐标需与查询图层的坐标系对应
var geometry = result.features[0].geometry;
geometry = JSON.stringify(geometry);
var geometryType = result.geometryType;
var url = "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer"
url += "/" + "5"+ "/query"; // states 查询
var params = {
"f": "json",
"geometry": geometry ,
"geometryType": geometryType,
"spatialRel": "esriSpatialRelIntersects", // 相交、可选择其他的
"returnGeometry": "true",
"outFields": "*"
};
$.ajax({
url:url,
type:'post',
data:params,
dataType: "json",
success: function(data){
console.log(data);
//var features = new ol.format.EsriJSON().readFeatures(data);
//console.log(features);
}
})
获取点(-100,40)所在的州?
Kansas(堪萨斯州)
// 坐标需与查询图层的坐标系对应
var center = [-100,40];// 坐标需与查询图层的坐标系对应
var geometry = "{'x':" + center[0] + ",'y':" + center[1] + "}";
var geometryType = "esriGeometryPoint";
var url = "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer"
url += "/" + "5"+ "/query"; // states 查询
var params = {
"f": "json",
"geometry": geometry ,
"geometryType": geometryType,
"spatialRel": "esriSpatialRelIntersects", // 相交、可选择其他的
"returnGeometry": "true",
"outFields": "*"
};
$.ajax({
url:url,
type:'post',
data:params,
dataType: "json",
success: function(data){
console.log(data);
//var features = new ol.format.EsriJSON().readFeatures(data);
//console.log(features);
}
})
从点(-100,40)到点(-80,40)之间,经过的州有哪些?
Nebraska、Pennsylvania、Indiana、Ohio、Illinois、West Virginia、Kansas、Missouri
内布拉斯加州,宾夕法尼亚州,印第安纳州,俄亥俄州,伊利诺伊州,西弗吉尼亚州,堪萨斯州,密苏里州
// 坐标需与查询图层的坐标系对应
// var geometry = {paths:[[[-100,40],[-80,40]]]};
// var geometryStr = JSON.stringify(geometry);
var geometry = '{"paths":[[[-100,40],[-80,40]]]}';
var geometryType = "esriGeometryPolyline";
var url = "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer"
url += "/" + "5"+ "/query"; // states 查询
var params = {
"f": "json",
"geometry": geometry,
"geometryType": geometryType ,
"spatialRel": "esriSpatialRelIntersects",
"returnGeometry": "true",
"outFields": "*"
};
$.ajax({
url:url,
type:'post',
data:params,
dataType: "json",
success: function(data){
console.log(data);
//var features = new ol.format.EsriJSON().readFeatures(data);
//console.log(features);
}
})
与华盛顿州相接触的州有哪些?
Oregon (俄勒冈州)、Idaho(爱达荷州)
// 坐标需与查询图层的坐标系对应
// Washington(华盛顿州)面数据
// var geometry = {rings:[[[x,y],[x1,y1]],[[x2,y2],[x3,y3]]]}
// var geometryStr = JSON.stringify(geometry);
var geometry = '{"rings":[[[-122.4020155875262,48.22521655312829],[-122.46285513210644,48.22836354491584],[-122.45441905150074,48.128492195019824],[-122.3613330982979,48.060097393916365],[-122.51451116740003,48.13397368404044],[-122.54207407642545,48.21046048331968],[-122.50913074806034,48.25379285277312],[-122.40440478982491,48.246594629689696],[-122.37832000545666,48.28972107808639],[-122.56436628706672,48.41424648838955],[-122.66703194684982,48.41289507641283],[-122.69941382303551,48.49432822898533],[-122.60817831012127,48.518824079856046],[-122.52322787048735,48.458403111914436],[-122.47383323692719,48.46219547842526],[-122.50529978754014,48.55944476686531],[-122.42954503114214,48.599397337177976],[-122.4877982072496,48.63857004948101],[-122.52655830037853,48.71172470933576],[-122.51685348704305,48.757921324129526],[-122.69740403352162,48.80301503092373],[-122.75424197507579,48.9099886110181],[-122.82242127137519,48.95072518366357],[-122.74394001657772,48.95580809240478],[-122.76511895841155,48.999746258295374],[-120.85705947154754,48.99983064707561],[-118.84360280150915,48.99989845856322],[-118.20035473766421,48.999908819371115],[-117.43858043030278,48.99991850672649],[-117.03204952594353,48.99993130232423],[-117.02911171886723,48.83807527955628],[-117.03886843985023,48.046185988970734],[-117.03747185475112,47.97109240752805],[-117.04179474642979,47.3614417498501],[-117.0423919433964,47.258501269637804],[-117.04096842019678,47.11931909786962],[-117.04192617327783,46.53660177472586],[-117.03855854808634,46.427980567157284],[-117.04447052867465,46.38857395961621],[-117.06418465948943,46.34869795567381],[-117.02797358412086,46.335426952263674],[-117.00164241974106,46.302448759780034],[-116.97272483508443,46.249309367621294],[-116.96749050313596,46.19755392037604],[-116.92942629366874,46.16548328285924],[-116.96163768276068,46.09727419923716],[-116.98721178290819,46.07850891120866],[-116.95772336954103,46.06568767046888],[-116.91913241660085,45.99517548286163],[-117.48166300067807,45.999834738168346],[-117.60282617340982,46.000268182566295],[-117.982677427616,45.99988053293921],[-117.99252775849826,46.001638917449725],[-118.98213281222488,45.99905835102935],[-119.03222167171751,45.9662745791057],[-119.14025060370322,45.92570864896612],[-119.17874266273213,45.92235159179867],[-119.3027635016912,45.9326627196117],[-119.37944140607192,45.91761007167733],[-119.43886110553936,45.91426850391767],[-119.51221997691755,45.89920057379166],[-119.58929428580802,45.913314946963794],[-119.62211670354507,45.89941032834733],[-119.67844567041178,45.85253901774398],[-119.83355587477269,45.84160934970011],[-119.8697356086974,45.831698511699784],[-119.9943201792136,45.811140337670494],[-120.0686478897373,45.780202447279976],[-120.15590785705729,45.76126164716587],[-120.20744536470863,45.71978406954033],[-120.28363486060556,45.71658289072753],[-120.44338375406954,45.689279727155835],[-120.49915650096483,45.695630695174316],[-120.57008244743506,45.74091794185985],[-120.6237571825373,45.74361056041752],[-120.65840336148264,45.73261251104159],[-120.69699389999052,45.71050979957657],[-120.86141966213461,45.665186238259395],[-120.9079372547567,45.63547708788022],[-120.94857280952527,45.65031599234788],[-120.96847851167789,45.64515454868288],[-121.03348258298826,45.65284439210055],[-121.07352990288905,45.64661076023138],[-121.1252046912449,45.60705910137989],[-121.17431600851339,45.600516147591264],[-121.19205464408839,45.61324191348636],[-121.20330813918277,45.65728695111031],[-121.21427173887247,45.66564496302858],[-121.27639089503077,45.67833995732427],[-121.31997772592592,45.69664284249678],[-121.36781424939201,45.699686588833735],[-121.42202904160537,45.690603164951256],[-121.44255214429995,45.694967085429155],[-121.52905463295534,45.71956768406761],[-121.70641684802291,45.68879318361746],[-121.75869411735738,45.689716072579984],[-121.81104101132085,45.700683091336295],[-121.88828347612332,45.67685639324294],[-121.92682070827462,45.642028382119186],[-121.97265946076396,45.63577610079583],[-122.00001157915293,45.617824291598566],[-122.08203752534868,45.59050403269385],[-122.24492227273171,45.548112839028846],[-122.30315032388003,45.543092820391514],[-122.3564575093225,45.56617126093927],[-122.4371542156704,45.5647789237714],[-122.5654298239963,45.59481879113833],[-122.65120918006521,45.60683043834983],[-122.69632309043479,45.631045563130854],[-122.76054129446695,45.64939740312063],[-122.77255102492899,45.72768553245908],[-122.76428853965942,45.760568042881886],[-122.78800955751231,45.80034359879181],[-122.78451589309287,45.8504495018134],[-122.78407364200822,45.86788643066273],[-122.8062229253047,45.90407243287622],[-122.80774176793686,45.9438901054702],[-122.87541773618912,46.02718333388263],[-122.89975729427287,46.07932969440945],[-122.97416923816469,46.1104834522323],[-123.05059620377838,46.15573624923161],[-123.11855414141729,46.179310506240796],[-123.1761963924877,46.18358646345973],[-123.21243704796278,46.170006034522046],[-123.24879939112651,46.14402035128124],[-123.30471708572415,46.14473757820721],[-123.47077301738115,46.27502380491162],[-123.62007645515783,46.25866548796735],[-123.72545892598501,46.28542382845632],[-123.88577092935763,46.24043839210453],[-123.9933294806653,46.31027474421332],[-124.07910754163322,46.267259260069096],[-124.065510639011,46.63974532677274],[-124.02304293077975,46.58354115583703],[-124.01300206464046,46.38368003201086],[-123.8414513303247,46.40434305741595],[-123.94069346835775,46.481115193344394],[-123.89356686744806,46.51107989305011],[-123.95771187237247,46.61722538557412],[-123.92647035850683,46.67306065994502],[-123.84096659992771,46.71828807296501],[-123.89554200005956,46.74498611355207],[-124.04315838748803,46.71585551068529],[-124.09104930519553,46.72902275060445],[-124.10206719551857,46.78946894711327],[-124.13882703107686,46.8999849392282],[-124.10576061631406,46.9081486859986],[-124.10473805637967,46.87414534337859],[-124.0288086167607,46.82376726193382],[-124.04692904810634,46.88725321586856],[-123.81265574418094,46.96396494828703],[-123.99586477035521,46.97638569199793],[-124.03439474994099,47.031033617785],[-124.11236153882282,47.04267502152666],[-124.16203638043227,46.92961265365739],[-124.19273369286367,47.166982440431894],[-124.23142535285652,47.27507053263065],[-124.31942694680504,47.349238220476536],[-124.34908009701759,47.52691012009184],[-124.37360573521099,47.63876353709284],[-124.48403495555985,47.808255060841084],[-124.60668516324358,47.87373510766577],[-124.73276977152562,48.149989058243655],[-124.7052096081143,48.23199588874885],[-124.71717571957514,48.377557624365274],[-124.56354721435014,48.357278829520666],[-123.9912157722483,48.159161636878],[-123.39685720077499,48.11103055564368],[-123.12322204799858,48.14873348373989],[-122.92159456183983,48.094179064244],[-122.92484438464565,48.06679638147177],[-122.84111113272226,48.13313642715511],[-122.76888257368049,48.14399398397609],[-122.80293145205115,48.085321505973454],[-122.661560715029,47.917157253519555],[-122.65358553496213,47.86443141300762],[-122.74586997606684,47.80898808799908],[-122.78980130382423,47.80254869048528],[-122.80951745499655,47.857075239407955],[-122.85880386991832,47.82732837568807],[-122.89936363537721,47.67251744326297],[-122.98274461983243,47.60547415774432],[-123.11391534870614,47.45627375820207],[-123.1540602156132,47.34854710278644],[-123.0104711260144,47.35302701250863],[-122.83324764216442,47.43846446191729],[-123.03620587048817,47.356051798567165],[-123.11268531359383,47.371569076931216],[-123.02633642391537,47.515936055986174],[-122.91696965261124,47.61460674366022],[-122.75294272976677,47.66068887152683],[-122.72306226342917,47.756899488976224],[-122.61116180836038,47.85000885760489],[-122.61321770346936,47.93618912513499],[-122.5318882625838,47.909461038205045],[-122.47358799660451,47.754980408335385],[-122.62150971704139,47.69696858724765],[-122.58646034725714,47.571191332331566],[-122.5552621933725,47.58350561874144],[-122.54270188957935,47.522734092864965],[-122.50446123555382,47.50721660728476],[-122.55844658767651,47.39836383565991],[-122.54412510195473,47.373927196806264],[-122.58825406212256,47.3339297123914],[-122.55315646277757,47.28333224083962],[-122.58053075329542,47.25138784976693],[-122.61154629794106,47.29339854276229],[-122.60691444697119,47.270571559021946],[-122.69974479904346,47.292085258558586],[-122.62875409752397,47.398553593856356],[-122.63743666174929,47.39858016932858],[-122.74154931196188,47.34145031201223],[-122.76970827826503,47.266156352544996],[-122.71980166538314,47.22313097382924],[-122.76123857683773,47.162496107008806],[-122.82510845050871,47.234826305575965],[-122.77333492365369,47.33736079753121],[-122.80218417878231,47.360740789392516],[-122.88037331060141,47.29923302450761],[-123.11543636710798,47.2079808824967],[-123.08119985450648,47.09005841505983],[-123.0313481539064,47.1007740806168],[-122.92314982271172,47.04796379952059],[-122.79004882352464,47.12585977228051],[-122.72818671901001,47.08244114910141],[-122.70007898690186,47.098325769909096],[-122.59180678314695,47.1800604219911],[-122.53076359688768,47.287456153202825],[-122.54658812500963,47.31627588002896],[-122.42409395109269,47.259472647181234],[-122.39284357873629,47.27772238140929],[-122.44160449348205,47.301125011635826],[-122.42083713474153,47.318844376108146],[-122.3253763289589,47.34432341584329],[-122.31973865075939,47.390114871244634],[-122.39263372057255,47.51024242942407],[-122.38222043519374,47.59540904731456],[-122.41481522598153,47.664179893940265],[-122.39449229409533,47.77417608432351],[-122.30292228249844,47.95021480979161],[-122.2301208743886,47.969113286005495],[-122.21699196945862,48.00743957210821],[-122.36833301551837,48.12814174069305],[-122.4020155875262,48.22521655312829]],[[-122.96797834462805,48.4437945282061],[-123.09523284353267,48.479422808131034],[-123.15971991052947,48.52184223499753],[-123.16989935247426,48.56256471694427],[-123.14105382723648,48.623647118861385],[-123.10372140163031,48.60837710117755],[-123.01209492363046,48.55747776748799],[-123.00869875441323,48.53371934711862],[-122.96798000235732,48.52693332877696],[-123.02227110192077,48.51335968616844],[-123.0188829105256,48.48960515110203],[-122.96797834462805,48.4437945282061]],[[-122.73318751834871,48.27664718904629],[-122.66561256797334,48.396777751860014],[-122.60438407866503,48.40478929836256],[-122.52575000195125,48.32104387248991],[-122.52864843795759,48.2835101363865],[-122.62350976739589,48.296350544620864],[-122.73203415321476,48.225414496362966],[-122.61092532292035,48.206321340568884],[-122.54620275476027,48.076858176443004],[-122.4962127373749,48.09407100101774],[-122.37999394938291,48.03214626541943],[-122.35539992985746,47.96388605121042],[-122.3869609192343,47.90454908279397],[-122.44278795676291,47.918056260819895],[-122.4716165420798,47.98750910762475],[-122.54496127095524,47.96753103522906],[-122.60862838361588,48.031430748026764],[-122.69555426668555,48.1811852435748],[-122.76877824034506,48.21881839162988],[-122.73318751834871,48.27664718904629]]]}';
var geometryType = "esriGeometryPolygon";
var url = "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer"
url += "/" + "5"+ "/query"; // states 查询
var params = {
"f": "json",
"geometry": geometry,
"geometryType": geometryType ,
"spatialRel": "esriSpatialRelTouches", //相接触
"returnGeometry": "true",
"outFields": "*"
};
$.ajax({
url:url,
type:'post',
data:params,
dataType: "json",
success: function(data){
console.log(data);
//var features = new ol.format.EsriJSON().readFeatures(data);
//console.log(features);
}
})
esriSpatialRelContains:Part or all of a feature from feature class 1 is contained within a feature from feature class 2.
esriSpatialRelCrosses:The feature from feature class 1 crosses a feature from feature class 2.
esriSpatialRelEnvelopeIntersects:The envelope of feature class 1 intersects with the envelope of feature class 2.
esriSpatialRelIndexIntersects:The envelope of the query feature class intersects the index entry for the target feature class.
esriSpatialRelIntersects:Part of a feature from feature class 1 is contained in a feature from feature class 2.
esriSpatialRelOverlaps:Features from feature class 1 overlap features in feature class 2.
esriSpatialRelRelation:Indicates that a spatial relationship function will be used.
esriSpatialRelTouches:The feature from feature class 1 touches the border of a feature from feature class 2.
esriSpatialRelWithin:The feature from feature class 1 is completely enclosed by the feature from feature class 2.
esriGeometryPoint,
esriGeometryPolyline,
esriGeometryPolygon,
esriGeometryEnvelope,
esriGeometryMultipoint.