GeoJSON (.geojson)
背景
-
- MIME 类型:application/geo+json.
- GeoJSON GIS 格式.
- 基于 JavaScript 对象注释(JSON)的地球空间数据交换格式.
- 用于表示简单地理学特性开放标准格式.
- GeoJSON 识别 Wolfram 语言中有规则列表的 GeoJSON 对象.
- GeoJSON 由 RFC 7946 指定.
Import
- Import["file.geojson"] 导入 GeoJSON 文件并将其渲染为 GeoGraphics 对象.
- Import["file.geojson","elem"] 从 GeoJSON 文件导入指定参数.
- Import["file.geojson",{{"elem1","elem2",…}}] 导入多个参数.
- Export["file.geojson",expr] 将 GeoGraphics 或 DynamicGeoGraphics 表达式导出到 GeoJSON 文件.
- 使用科学注释的坐标数字在 JSON 中以 E 符号表示.
- 请到以下参考页面了解完整的基本信息:
-
Import, Export 从文件导入或导出到文件 CloudImport, CloudExport 从云对象导入或导出到云对象 ImportString, ExportString 从字符串导入或导出到字符串 ImportByteArray, ExportByteArray 从字节数组导入或导出到字节数组
参数
- Import 的通用参数:
-
"Elements" 该文件可用的参数和选项列表 "Summary" 文件摘要 "Rules" 所有可用参数的规则列表 - 数据表示参数:
-
"Data" 基于规则的每个 GeoJSON 文档特性表示 "Graphics" 所有地理特性合并在单个 GeoGraphics 对象 "GraphicsList" 表示 GeoJSON 文档地理学特性的图像列表 - 默认情况下 Import 对 GeoJSON 格式使用 "Graphics" 参数.
- 空间信息参数:
-
"CoordinateSystem" 坐标参照系统名称 "SpatialRange" 地理坐标范围,通常以十进制度数给出 - 文件中的低等级元信息:
-
"CoordinateSystemInformation" 坐标参照系统的原始参数
范例
打开所有单元 关闭所有单元基本范例 (3)
Import["ExampleData/newyork.geojson"]将 GeoGraphics 对象导出为 GeoJSON 文件:
file = FileNameJoin[{$TemporaryDirectory, "marker.geojson"}]Export[file, GeoGraphics[GeoMarker[Entity["City", {"Boston", "Massachusetts", "UnitedStates"}]]]]Import[file]FilePrint[file]Import["ExampleData/lineNYCtoBoston.geojson", "String"]将字符串作为 GeoGraphics 对象导入并诠释:
ImportString[%, "GeoJSON"]范围 (6)
将 GeoGraphics 地图导出为 GeoJSON 文件:
file = FileNameJoin[{$TemporaryDirectory, "polygonBoston.geojson"}]Export[file, GeoGraphics[Polygon[Entity["City", {"Boston", "Massachusetts", "UnitedStates"}]]]]Import[file]用 GeoJSON 格式将 GeoGraphics 对象导出为字符串:
ExportString[GeoGraphics[GeoMarker[Entity["City", {"Boston", "Massachusetts", "UnitedStates"}]]], "GeoJSON"]明确指定 GeoJSON 格式将 GeoGraphics 对象导出为 JSON 文件:
file = FileNameJoin[{$TemporaryDirectory, "marker.json"}]Export[file, GeoGraphics[GeoMarker[Entity["City", {"Boston", "Massachusetts", "UnitedStates"}]]], "GeoJSON"]Import[file]Import[file, "GeoJSON"]将含有图像指示的 GeoGraphics 表达式导出,GeoJSON 属性进行编码:
file = FileNameJoin[{$TemporaryDirectory, "polygonWithDirectives.geojson"}]Export[file, GeoGraphics[{FaceForm[Blue], EdgeForm[Red], Polygon[Entity["City", {"Boston", "Massachusetts", "UnitedStates"}]]}]]将 GeoGraphics 数据导回:
Import[file]Import[file, "Data"]导出不同类型的 GeoGraphics 基元和指令:
file = FileNameJoin[{$TemporaryDirectory, "geopath.json"}]Export[file, GeoGraphics[{Red, Opacity[0.5], Thickness[Large], GeoPath[{Entity["City", {"NewYork", "NewYork", "UnitedStates"}], Entity["City", {"Boston", "Massachusetts", "UnitedStates"}]}], Blue, Point[Entity["City", {"NewYork", "NewYork", "UnitedStates"}]], FaceForm[{Blue, Opacity[0.7]}], EdgeForm[{Red, Dashed, Thickness[Medium]}], Polygon[Entity["City", {"NewYork", "NewYork", "UnitedStates"}]], Red, Point[Entity["City", {"Boston", "Massachusetts", "UnitedStates"}]], FaceForm[{Red, Opacity[0.7]}], EdgeForm[{Blue, Dashed, Thickness[Medium]}], Polygon[Entity["City", {"Boston", "Massachusetts", "UnitedStates"}]]}], "GeoJSON"]Import[file, "GeoJSON"]Import["ExampleData/map.geojson", "Elements"]Import["ExampleData/map.geojson", "SpatialRange"]Import["ExampleData/map.geojson", {{"Graphics", "SpatialRange"}}]导入参数 (4)
"Data" (1)
"Graphics" (1)
导入 GeoJSON 文件的 GeoGraphics 版本:
Import["ExampleData/newyork.geojson", "Graphics"]"GraphicsList" (1)
将 GeoJSON 文件作为完整 GeoGraphics 对象导入:
Import["ExampleData/disks.geojson"]对于相应地理基元,导入 GeoGraphics 对象列表:
Import["ExampleData/disks.geojson", "GraphicsList"]"SpatialRange" (1)
Import["ExampleData/boston.geojson", "SpatialRange"]FilePrint["ExampleData/boston.geojson"]该 GeoJSON 文件仅包含在导入 GeoGraphics 时使用的边界框信息:
Import["ExampleData/boston.geojson"]导出选项 (1)
应用 (1)
earthquakes = EarthquakeData[GeoDisk[Entity["City", {"Sacramento", "California", "UnitedStates"}], Quantity[600, "Kilometers"]], 4, {{1972, 1, 1}, {2012, 12, 31}}, "Position"]["Values"];将数据的 GeoGraphics 图导出为 GeoJSON 文件,从而使其可用于其他应用:
file = FileNameJoin[{$TemporaryDirectory, "earthquakes.geojson"}]Export[file, GeoGraphics[{Red, PointSize[.015], Point[earthquakes]}]]验证结果,导入 GeoJSON 文件的 "Data" 参数:
Import[file, "Data"]用简化地理背景导入 GeoJSON 文件,来显示带地形图的相关性:
Import[file, GeoBackground -> "ReliefMap"]历史
2017年引入 (11.2)