我试图渲染具有不同填充颜色但仍来自geoJson的多边形,并且在动态渲染后也可以这样做.我真的希望看到这两种方法.
我当前的代码在geojson中设置了颜色,但它只是渲染为默认值(黑色).
<!DOCTYPE html>
<html>
<head>
<script src="http://maps.googleapis.com/maps/api/js"></script>
<script>
var x=new google.maps.LatLng(40.75597,-73.974228);
function initialize()
{
var data = {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"fillColor": "blue"
},
"geometry": {"type":"Polygon","coordinates":[[[-73.98779153823898,40.718233223261],[-74.004946447098,40.723575517498],[-74.006771211624,40.730592217474],[-73.99010896682698,40.746712376146], [-73.973135948181,40.73974615047701],[-73.975120782852,40.736128627654],[-73.973997695541,40.730787341083],[-73.983317613602,40.716639396436],[-73.98779153823898,40.718233223261]]]}
},
{
"type": "Feature",
"properties": {
"fillColor": "red"
},
"geometry": {"type":"MultiPolygon","coordinates":[[[[-73.98779153823898,40.718233223261],[-73.987373113632,40.718062457927],[-73.986815214157,40.717785979789],[-73.989978364944,40.71747697345301],[-73.983317613602,40.716639396436],[-73.983081579208,40.717111043043],[-73.982888460159,40.717346865093],[-73.982352018356,40.718347066574],[-73.98201942443798,40.719119569628],[-73.981890678406,40.719477357478],[-73.981322050095,40.72055070949],[-73.981043100357,40.720941015022],[-73.98057103156998,40.721599650417],[-73.98014187812798,40.72217696744],[-73.979691267014,40.722803066157],[-73.978382349014,40.724600018078],[-73.977502584457,40.725795248823],[-73.97659063339198,40.727006719305],[-73.97616147994998,40.727673425196],[-73.975646495819,40.728340124407],[-73.973972797394,40.730657258741],[-73.973897695541,40.730787341083],[-73.973962068558,40.731080025424],[-73.974262475967,40.732242619953],[-73.974434137344,40.732811714764],[-73.975056409836,40.735128693386],[-73.975120782852,40.735746540724],[-73.975120782852,40.736128627654],[-73.975002765656,40.736648912711],[-73.974788188934,40.737039123833],[-73.973811864853,40.738453619965],[-73.973361253738,40.739128340284],[-73.973243236542,40.739429117016],[-73.973135948181,40.73974615047701],[-73.97337198257398,40.739884344077],[-73.97344708442698,40.739868086021],[-73.97357583046,40.739876215049],[-73.97401571273798,40.740095698439],[-73.97419810295098,40.740136343432],[-73.974477052689,40.74012821443501],[-73.975796699524,40.74070537072101],[-73.980302810669,40.742591254937],[-73.983424901962,40.74393247626],[-73.988628387451,40.746119015457],[-73.99010896682698,40.746712376146],[-73.99053812027,40.746143400247],[-73.99099946022,40.74549313611601],[-73.9923620224,40.74363984846],[-73.999196653366,40.741111815805],[-73.995484113693,40.739355955233],[-73.996857404709,40.737445591319],[-73.998284339905,40.735486395176],[-74.00009751319898,40.733014961731],[-74.000591039658,40.732291399699],[-74.000998735428,40.731771080565],[-74.001084566116,40.731641000145],[-74.001771211624,40.730592217474],[-74.00286555290198,40.72847021127901],[-74.003208875656,40.727705947263],[-74.00350928306598,40.727006719305],[-74.004056453705,40.725600110575],[-74.00466799736,40.724160948332],[-74.00488257408098,40.723705613684],[-74.004946947098,40.723575517498],[-74.003230333328,40.72327466909401],[-74.003080129623,40.723266538038],[-74.002522230148,40.723030736958],[-73.99914264679,40.721380106009],[-73.998337984085,40.721022328386],[-73.997876644135,40.721526469028],[-73.997340202332,40.72134758085],[-73.994904756546,40.72053444671],[-73.99302721023598,40.719867669303],[-73.990634679794,40.719127701191],[-73.98779153823898,40.718233223261]]]]}
}
]
};
var mapProp = {
center: new google.maps.LatLng(40.75597, -73.974228),
zoom: 12,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("googleMap"), mapProp);
map.data.addGeoJson(data);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="googleMap" style="width:500px;height:380px;"></div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud) 因此,我正在尝试使用带有 geojson 的传单作为坐标来映射公交路线。我在一个方面遇到了困难,点击后,总线线路被加粗,理想情况下,最后一次点击的功能会返回到默认样式。
到目前为止我所拥有的
function $onEachFeature(feature, layer) {
layer.on({
click: function(e) {
//calls up the feature clicked on
var $layer = e.target;
var highlightStyle = {
opacity: 1,
weight: 5
};
$layer.bringToFront();
$layer.setStyle(highlightStyle);
}
});
}
//imagine all the leaflet map tile code here
//this is where the features get added in and the $oneachfeature function
var busFeature = L.geoJson(busRoutes, {
style: defaultBusRouteColor,
onEachFeature : $onEachFeature
});
busFeature.addTo(map);
Run Code Online (Sandbox Code Playgroud)
上面,我现在成功地将功能的样式更改为highlightStyle. 但是,当单击另一个特征时,该样式将保留。如何删除之前单击的要素样式,以便一次只有一个要素具有该样式highlightStyle?
我已经尝试过的事情:使用 addClass/removeClass 到 jQuery 方法,layer.resetStyle() …
我刚接触地图,我已经开始按照http://leafletjs.com上的文档和教程创建我的地图。到目前为止一切顺利,我已经设法创建了一张地图,从 geojson.io 添加了大量 geosjon 数据,在弹出窗口中显示“popupContent”。它有效。
但我无法理解如何创建几个图层来对所有这些标记进行排序。我想要的是太使用“属性”来做到这一点。我有名为“status”的属性,其值为“done”、“new”和“active”。
像这样:
"type": "Feature",
"properties": {
"popupContent": "content",
"marker-color": "#FFFFFF",
"title": "title of project",
"status": "active
Run Code Online (Sandbox Code Playgroud)
那可能吗?根据“状态”属性创建 3 个图层?
如果您需要查看 html 文件,请说出来,我可以添加它。
谢谢
我有一个Feature Collection,Polygons我MultiPolygons必须首先将其写入临时文件中,然后使用 geopandas.GeoDataFrame.from_file(tmp_json_file) 加载它,我正在寻找一种无需临时文件即可完成此操作的方法。我尝试过使用geopandas.GeoDataFrame.from_feature(),它对于简单多边形的特征集合工作得很好,但我不能让它适用于Feature Collection和Polygons,MultiPolygons我正在考虑做类似下面的事情,但它还没有工作。
features_collection = []
for feature in json_data['features']:
tmp_properties = {'id': feature['properties']['id']}
if is_multipolygon (feature):
tmp = Feature(geometry=MultiPolygon((feature['geometry']['coordinates'])), properties=tmp_properties)
else:
Feature(geometry=Polygon((feature['geometry']['coordinates'])), properties=tmp_properties)
features_collection.append(tmp)
collection = FeatureCollection(features_collection)
return geopandas.GeoDataFrame.from_features(collection['features'])
Run Code Online (Sandbox Code Playgroud)
GeoJSON 取自 API,返回领土(某些领土由单个多边形建模,其他由一组多边形(格式为 MultiPolygon)建模。
GeoJSON 的结构如下: http: //pastebin.com/PPdMUGkY
我从上面的函数中收到以下错误:
Traceback (most recent call last):
File "overlap.py", line 210, in <module>
print bdv_json_to_geodf(contours_bdv)
File "overlap.py", line 148, in json_to_geodf
return geopandas.GeoDataFrame.from_features(collection['features'])
File "/Library/Python/2.7/site-packages/geopandas/geodataframe.py", line 179, …Run Code Online (Sandbox Code Playgroud) 我需要创建将使用 GeoJSON 数据(MultiLineString 格式)作为 Google 地图上的数据层的地图。我创建了一个 Google Maps JavaScript API 项目,并有一个 API 密钥。
我尝试了以下示例:
示例 I:
https : //developers.google.com/maps/documentation/javascript/examples/layer-data-simple
(这会呈现多边形,但似乎不支持 MultiLineString 的样式)。
示例二:
https : //developers.google.com/maps/documentation/javascript/examples/layer-data-dragndrop
(此示例允许通过拖放添加 GeoJSON,但我不知道如何保存地图和数据层。)
来自http://geojsonlint.com 的示例 GeoJSON MultiLineString :
{
"type": "MultiLineString",
"coordinates": [
[
[
-105.0214433670044,
39.57805759162015
],
[
-105.02150774002075,
39.57780951131517
],
[
-105.02157211303711,
39.57749527498758
],
[
-105.02157211303711,
39.57716449836683
],
[
-105.02157211303711,
39.57703218727656
],
[
-105.02152919769287,
39.57678410330158
]
],
[
[
-105.01989841461182,
39.574997872470774
],
[
-105.01959800720215,
39.57489863607502
],
[
-105.01906156539916,
39.57478286010041
]
], …Run Code Online (Sandbox Code Playgroud) 我正在尝试聚合多个位置 API 系统(Google、Foursquare 等),为用户提供不同的位置数据。交付基于用户位置,从而产生纬度、经度和半径搜索。
我在网上搜索了特定的 API 聚合想法,但运气不太好,我只找到了许多用于服务器端 HTTP 请求的聪明的库。我具体寻找的是关于 geoJson 聚合最佳实现的意见。
我的选择(据我所知)是:
1.在前端向用户公开多个基于位置的 API(Google、Foursquare 等),即每次用户移动到该位置时查询 API。
2.以某种方式根据用户位置(大部分是静态的)在服务器上聚合 API 调用,根据需要使用“cron job”更新聚合。因此,数据传输被有效地预先缓存,并且可以根据用户偏好更容易地分页。
我意识到我可以通过http.get在后端填充数据库(假设由于地理空间查询而使用 mongo)的调用来实现这一点。这似乎是一个常见的用例,我找不到任何参考。
有人在 Node 中有这方面的经验吗?我觉得我错过了一些东西。谢谢
我使用Google Maps Javascript API创建了html页面.此地图显示geojson文件中的标记.一切都很好.我想添加标记聚类.但由于某种原因,这不起作用.我对Javascript不太满意.请告诉我如何更改我的代码.
var map;
function initMap() {
var styleArray = [
{
featureType: 'all',
stylers: [
{ saturation: -80 }
]
},{
featureType: 'road.arterial',
elementType: 'geometry',
stylers: [
{ hue: '#00ffee' },
{ saturation: 50 }
]
},{
featureType: 'poi.business',
elementType: 'labels',
stylers: [
{ visibility: 'off' }
]
}
];
var mapOptions = {
zoom: 14,
center: new google.maps.LatLng(42.34, -71.05),
styles: styleArray
};
var map = new google.maps.Map(document.getElementById('map'),
mapOptions);
// Load GeoJSON.
map.data.loadGeoJson('/map.geojson');
map.data.setStyle(function(feature) {
return {icon:feature.getProperty('icon')}; …Run Code Online (Sandbox Code Playgroud)我正在序列化一个Typescript类对象:
class Geometry {
public abstract type: string;
public abstract coordinates: Coordinates | number[];
}
class Point extends Geometry {
public readonly type: string = "Point";
constructor(public coordinates: Coordinate | number[]) {
super();
}
}
Run Code Online (Sandbox Code Playgroud)
运用 JSON.stringify(new Point([10, 10]));
到目前为止,这很好,但最终被插入GeoJSON对象并且属性的顺序很重要.我得到的是:
{"coordinates":[10,10],"type":"Point"}
Run Code Online (Sandbox Code Playgroud)
我需要的是:
{"type":"Point","coordinates":[10,10]}
Run Code Online (Sandbox Code Playgroud)
如果不在public coordinates构造函数中声明并分配它们:
constructor(coordinates: Coordinate | number[]) {
super();
this.coordinates = coordinates;
}
Run Code Online (Sandbox Code Playgroud)
结果是对的.作为一个极简主义者,我试图使用public参数使用构造函数.
有没有办法控制JSON.stringify(-)方法中属性的顺序?
给自己一个替代的答案
真正的问题在于properties特征的价值(在原始问题的范围之外).通过覆盖toJSON对象上的方法,可以控制对象如何序列化自身.我在Geometry课堂上添加了以下内容,一切都很顺利.
public toJSON() {
return {
type: this.type, …Run Code Online (Sandbox Code Playgroud) 如果已经回答,请提前道歉。我在网上或存储库中找不到任何指向我的问题的内容。
我有一个ArrayList<Position>固定我的线刺。
绘制时此显示很好 addPolyline
我想设置线条的样式,所以我切换到使用线条图层。然而。
这条线不再出现在靠近正确位置的任何地方。该地点位于英格兰坎布里亚郡,但取材于索马里海岸。
我试图在每次转换后输出坐标,它们都显示正常。我不知道如何检查source
Log.d("Tracing 1", route.toString())
val lineString = LineString.fromCoordinates(route)
Log.d("Tracing 2", lineString.coordinates.toString())
val feature = Feature.fromGeometry(lineString)
Log.d("Tracing 3", feature.geometry.coordinates.toString())
val featureCollection = FeatureCollection.fromFeatures(
arrayOf(feature))
val geoJsonSource: Source = GeoJsonSource("line-source", featureCollection)
mapboxMap.addSource(geoJsonSource)
val debugSource = mapboxMap.getSource("line-source") as GeoJsonSource
Log.d("Tracing 4", debugSource.toString())
val lineLayer = LineLayer("linelayer", "line-source")
lineLayer.setProperties(
PropertyFactory.lineDasharray(arrayOf(0.01f, 2f)),
PropertyFactory.lineCap(LINE_CAP_ROUND),
PropertyFactory.lineJoin(LINE_JOIN_ROUND),
PropertyFactory.lineWidth(5f),
PropertyFactory.lineColor(Color.parseColor("#e55e5e"))
)
mapboxMap.addLayer(lineLayer)
val cameraPosition = CameraPosition.Builder()
.target(LatLng(route[0].latitude, route[0].longitude))
.build()
mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition))
Run Code Online (Sandbox Code Playgroud)
显示Logs 全部相同的日志 cat 输出在这里。
10-05 20:52:37.162 11449-11449/com.xxx.xxx D/Tracing …Run Code Online (Sandbox Code Playgroud) 我正在尝试减小 geoJSON 文件的大小,以便我的网站查看者可以非常快速地查看页面中的地图。
您可以在此处找到有关 geoJSON 格式的更多信息http://geojson.org/
我读了一篇博客,建议使用记事本 ++ 减少 GeoJSON 文件中小数点后的位数。
我可以找到删除数字中所有小数位的答案。但我的问题是我想保留一个数字的前 5 个小数位并删除其他的。
EG:-103.3751447563353
更换后:-103.37514
编辑: 我尝试了答案,但我的记事本 ++ 说“找不到文本”。我已确保选中正则表达式复选框,但仍然没有运气这将为每个纬度或经度坐标节省 10 个以上的字符。
请分享您的答案
我有以下 GeoJSON 数据文件,其中包含一个带坐标的多边形。
[
{
"geometry": {
"type": "Polygon",
"coordinates":
[
[
[
9.137248,
48.790411
],
[
9.137248,
48.790263
],
[
9.13695,
48.790263
],
[
9.137248,
48.790411
]
]
]
}
}
]
Run Code Online (Sandbox Code Playgroud)
在 的帮助下org.geotools.geojson.geom.GeometryJSON,我正在解析com.vividsolutions.jts.geom.Polygon类中的 JSON 坐标,如下所示。并检查是否Coordinate(9.13710, 48.790360)在这个多边形内。
GeometryJSON g = new GeometryJSON();
com.vividsolutions.jts.geom.Polygon polygon = g.readPolygon(new File(fileLocation));
System.out.println("Type="+polygon.getGeometryType());
GeometryFactory gf = new GeometryFactory();
boolean pointIsInPolygon = polygon.contains(gf.createPoint(new Coordinate(9.13710, 48.790360)));
System.out.println("Point is in polygon="+pointIsInPolygon);
Run Code Online (Sandbox Code Playgroud)
但是我的程序总是给我下面的结果,即给定的坐标不在多边形中。
类型=多边形
a) 你能看出为什么pointIsInPolygon是假的。我错过了什么吗?
b) 我应该在这里给出什么坐标,所以 …
属于这个问题的代码可以在github上找到.
我编写了一个脚本,用于解析csv文件中的地址,使用geopy查询相应的坐标(经度和纬度),并将输出写入JSON格式的文本文件.
将数据写入JSON文件的print语句不漂亮:
print('{"type": "Feature","geometry": { "coordinates": ['+str(location.longitude)+
','+str(location.latitude)+ ',],"type": "Point"},"properties": {"title": "dentist #1","privat": true,"marker-color": "#6699ff","marker-size": "large","marker-symbol": "dentist"}},')
time.sleep(0.01)
file.write('{"type": "Feature","geometry": { "coordinates": ['+str(location.longitude)+
','+str(location.latitude)+ ',],"type": "Point"},"properties": {"title": "dentist #1","privat": true,"marker-color": "#6699ff","marker-size": "large","marker-symbol": "dentist"}},')
Run Code Online (Sandbox Code Playgroud)
必须有更好(更简单)的方法来做到这一点.我已经开始谷歌了,但我对我发现的东西不满意.有没有人建议如何更优雅地处理Python中的JSON?