OpenersPrimaryExamplesSection(Spacer1)Examples  (15)

OpenersExampleSection0(Spacer1)Basic Examples  (3)

Import the contents of a GeoJSON file:

Import["ExampleData/newyork.geojson"]

Export a (RefLink[GeoGraphics, paclet:ref/GeoGraphics]) object as a GeoJSON file:

file=FileNameJoin[{$TemporaryDirectory,"marker.geojson"}]

Export[file,GeoGraphics[GeoMarker[(Entity["Boston", Entity["City",{"Boston","Massachusetts","UnitedStates"}], "Entity[\"City\", {\"Boston\", \"Massachusetts\", \"UnitedStates\"}]", "city"])]]]

Import the GeoJSON file:

Import[file]

Print the GeoJSON code:

FilePrint[file]

Read a GeoJSON file as a string:

Import["ExampleData/lineNYCtoBoston.geojson","String"]

Import the string and interpret it as a (RefLink[GeoGraphics, paclet:ref/GeoGraphics]) object:

ImportString[%,"GeoJSON"]

OpenersExampleSection1(Spacer1)Scope  (6)

Export a (RefLink[GeoGraphics, paclet:ref/GeoGraphics]) map as a GeoJSON file:

file=FileNameJoin[{$TemporaryDirectory,"polygonBoston.geojson"}]

Export[file,GeoGraphics[Polygon[(Entity["Boston", Entity["City",{"Boston","Massachusetts","UnitedStates"}], "Entity[\"City\", {\"Boston\", \"Massachusetts\", \"UnitedStates\"}]", "city"])]]]

Import the file:

Import[file]

Export a (RefLink[GeoGraphics, paclet:ref/GeoGraphics]) object as a string using the GeoJSON format:

ExportString[GeoGraphics[GeoMarker[(Entity["Boston", Entity["City",{"Boston","Massachusetts","UnitedStates"}], "Entity[\"City\", {\"Boston\", \"Massachusetts\", \"UnitedStates\"}]", "city"])]],"GeoJSON"]

Specify explicitly the GeoJSON format to export a (RefLink[GeoGraphics, paclet:ref/GeoGraphics]) object to a JSON file:

file=FileNameJoin[{$TemporaryDirectory,"marker.json"}]

Export[file,GeoGraphics[GeoMarker[(Entity["Boston", Entity["City",{"Boston","Massachusetts","UnitedStates"}], "Entity[\"City\", {\"Boston\", \"Massachusetts\", \"UnitedStates\"}]", "city"])]],"GeoJSON"]

Import the file as pure JSON:

Import[file]

Import the file as GeoJSON:

Import[file,"GeoJSON"]

Export a (RefLink[GeoGraphics, paclet:ref/GeoGraphics]) expression containing graphical directives, encoded as GeoJSON properties:

file=FileNameJoin[{$TemporaryDirectory,"polygonWithDirectives.geojson"}]

Export[file,GeoGraphics[{FaceForm[Blue],EdgeForm[Red],Polygon[(Entity["Boston", Entity["City",{"Boston","Massachusetts","UnitedStates"}], "Entity[\"City\", {\"Boston\", \"Massachusetts\", \"UnitedStates\"}]", "city"])]}]]

Import back the (RefLink[GeoGraphics, paclet:ref/GeoGraphics]) data:

Import[file]

Import a particular element from a GeoJSON file:

Import[file,"Data"]

Export (RefLink[GeoGraphics, paclet:ref/GeoGraphics]) primitives and directives of different types:

file=FileNameJoin[{$TemporaryDirectory,"geopath.json"}]

Export[file,GeoGraphics[{Red,Opacity[0.5],Thickness[Large],GeoPath[{(Entity["New York City", Entity["City",{"NewYork","NewYork","UnitedStates"}], "Entity[\"City\", {\"NewYork\", \"NewYork\", \"UnitedStates\"}]", "city"]),(Entity["Boston", Entity["City",{"Boston","Massachusetts","UnitedStates"}], "Entity[\"City\", {\"Boston\", \"Massachusetts\", \"UnitedStates\"}]", "city"])}],Blue,Point[(Entity["New York City", Entity["City",{"NewYork","NewYork","UnitedStates"}], "Entity[\"City\", {\"NewYork\", \"NewYork\", \"UnitedStates\"}]", "city"])],FaceForm[{Blue,Opacity[0.7]}],EdgeForm[{Red,Dashed,Thickness[Medium]}],Polygon[(Entity["New York City", Entity["City",{"NewYork","NewYork","UnitedStates"}], "Entity[\"City\", {\"NewYork\", \"NewYork\", \"UnitedStates\"}]", "city"])],Red,Point[(Entity["Boston", Entity["City",{"Boston","Massachusetts","UnitedStates"}], "Entity[\"City\", {\"Boston\", \"Massachusetts\", \"UnitedStates\"}]", "city"])],FaceForm[{Red,Opacity[0.7]}],EdgeForm[{Blue,Dashed,Thickness[Medium]}],Polygon[(Entity["Boston", Entity["City",{"Boston","Massachusetts","UnitedStates"}], "Entity[\"City\", {\"Boston\", \"Massachusetts\", \"UnitedStates\"}]", "city"])]}],"GeoJSON"]

Import the file:

Import[file,"GeoJSON"]

Give the list of possible elements to import from a GeoJSON file:

Import["ExampleData/map.geojson","Elements"]

Import one element:

Import["ExampleData/map.geojson","SpatialRange"]

Import several elements:

Import["ExampleData/map.geojson",{{"Graphics","SpatialRange"}}]

OpenersExampleSection2(Spacer1)Import Elements  (4)

OpenersExampleSubsection0(Spacer1)"Data"  (1)

The "Data" element returns the data in the GeoJSON file, interpreted as Wolfram Language expressions:

Import["ExampleData/newyork.geojson","Data"]

OpenersExampleSubsection1(Spacer1)"Graphics"  (1)

Import the (RefLink[GeoGraphics, paclet:ref/GeoGraphics]) version of a GeoJSON file:

Import["ExampleData/newyork.geojson","Graphics"]

OpenersExampleSubsection2(Spacer1)"GraphicsList"  (1)

Import a GeoJSON file as a complete (RefLink[GeoGraphics, paclet:ref/GeoGraphics]) object:

Import["ExampleData/disks.geojson"]

Import a list of (RefLink[GeoGraphics, paclet:ref/GeoGraphics]) objects for the respective geo primitives:

Import["ExampleData/disks.geojson","GraphicsList"]

OpenersExampleSubsection3(Spacer1)"SpatialRange"  (1)

Get the spatial range used in a GeoJSON file:

Import["ExampleData/boston.geojson","SpatialRange"]

Compare to the GeoJSON specification of that geo range:

FilePrint["ExampleData/boston.geojson"]

That GeoJSON file contains only bounding box information, which is used when importing to (RefLink[GeoGraphics, paclet:ref/GeoGraphics]):

Import["ExampleData/boston.geojson"]

OpenersExampleSection5(Spacer1)Export Options  (1)

OpenersExampleSubsection4(Spacer1)"Compact"  (1)

Return a compact form of the code by limiting indentation:

ExportString[GeoGraphics[Point[(Entity["Boston", Entity["City",{"Boston","Massachusetts","UnitedStates"}], "Entity[\"City\", {\"Boston\", \"Massachusetts\", \"UnitedStates\"}]", "city"])]], "GeoJSON","Compact"->True]

OpenersExampleSection6(Spacer1)Applications  (1)

Download earthquake data for the East Coast of the US:

earthquakes=EarthquakeData[GeoDisk[(Entity["Sacramento", Entity["City",{"Sacramento","California","UnitedStates"}], "Entity[\"City\", {\"Sacramento\", \"California\", \"UnitedStates\"}]", "city"]),Quantity[600,"Kilometers"]],4,{{1972,1,1},{2012,12,31}},"Position"]["Values"];

Export a (RefLink[GeoGraphics, paclet:ref/GeoGraphics]) map of the data as a GeoJSON file, so that it can be used in other applications:

file=FileNameJoin[{$TemporaryDirectory,"earthquakes.geojson"}]

Export[file,GeoGraphics[{Red,PointSize[.015],Point[earthquakes]}]]

Verify the result, importing the "Data" element of the GeoJSON file:

Import[file,"Data"]

Import the GeoJSON file using a relief geo background, to show correlation with the topography:

Import[file,GeoBackground->"ReliefMap"]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {Related Formats:  (RefLink[SHP, paclet:ref/format/SHP])  ▪  (RefLink[KML, paclet:ref/format/KML])  ▪  (RefLink[GPX, paclet:ref/format/GPX])  ▪  (RefLink[JSON, paclet:ref/format/JSON])  ▪  (RefLink[RawJSON, paclet:ref/format/RawJSON])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Geospatial Formats, paclet:guide/GeospatialFormats])}, {▪(RefLinkPlain[Graphics Importing & Exporting, paclet:guide/GraphicsImportingAndExporting])}, {▪(RefLinkPlain[Importing & Exporting, paclet:guide/ImportingAndExporting])}, {▪(RefLinkPlain[Listing of All Formats, paclet:guide/ListingOfAllFormats])}, {▪(RefLinkPlain[New in 6.0: Data Handling & Data Sources, paclet:guide/NewIn60DataHandlingAndDataSources])}, {▪(RefLinkPlain[New in 6.0: Import & Export Formats, paclet:guide/NewIn60ImportAndExportFormats])}})}})