You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/azure-maps/spatial-io-read-write-spatial-data.md
+19-18Lines changed: 19 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,9 +13,7 @@ manager: philmea
13
13
14
14
# Read and write spatial data
15
15
16
-
This article outlines all the different tools available in the Spatial IO module for reading and writing spatial data.
17
-
18
-
The following table is a list of spatial file formats that are supported for reading and writing using the Spatial IO module.
16
+
The table below lists the spatial file formats that are supported for reading and writing operations with the Spatial IO module.
19
17
20
18
| Data Format | Read | Write |
21
19
|-------------------|------|-------|
@@ -28,9 +26,11 @@ The following table is a list of spatial file formats that are supported for rea
28
26
| Spatial CSV | ✓ | ✓ |
29
27
| Well Known Text | ✓ | ✓ |
30
28
31
-
## Read spatial data
29
+
These next sections outline all the different tools for reading and writing spatial data using the Spatial IO module.
30
+
31
+
## Read spatial data
32
32
33
-
The `atlas.io.read` function is used to read common spatial data formats such as KML, GPX, GeoRSS, GeoJSON, and CSV files with spatial data. This function can also as read compressed versions of these formats, as a zip file or a KMZ file. The KMZ file format is a compressed version of KML that can also include assets such as images. Alternatively, the read function can take in a URL that points to a file in any of these formats. URLs should be hosted on a CORs enabled endpoint, or a proxy service should be provided in the read options. The read function returns a promise to add the image icons to the map, and processes in asynchronously to minimize impact to the UI thread.
33
+
The `atlas.io.read` function is the main function used to read common spatial data formats such as KML, GPX, GeoRSS, GeoJSON, and CSV files with spatial data. This function can also read compressed versions of these formats, as a zip file or a KMZ file. The KMZ file format is a compressed version of KML that can also include assets such as images. Alternatively, the read function can take in a URL that points to a file in any of these formats. URLs should be hosted on a CORs enabled endpoint, or a proxy service should be provided in the read options. The proxy service is used to load resources on domains that aren't CORs enabled. The read function returns a promise to add the image icons to the map, and processes data asynchronously to minimize impact to the UI thread.
34
34
35
35
When reading a compressed file, either as a zip or a KMZ, it will be unzipped and scanned for the first valid file. For example, doc.kml, or a file with other valid extension, such as: .kml, .xml, geojson, .json, .csv, .tsv, or .txt. Then, images referenced in KML and GeoRSS files are preloaded to ensure they're accessible. Inaccessible image data may load an alternative fallback image or will be removed from the styles. Images extracted from KMZ files will be converted to data URIs.
36
36
@@ -48,21 +48,21 @@ The result from the read function is a `SpatialDataSet` object. This object exte
48
48
49
49
## Examples of reading spatial data
50
50
51
-
The following code shows how to read a simple spatial data set, and render it on the map using the `SimpleDataLayer` class. The code uses a GPX file pointed it to by a URL.
51
+
The following code shows how to read a simple spatial data set, and render it on the map using the `SimpleDataLayer` class. The code uses a GPX file pointed to by a URL.
52
52
53
53
<br/>
54
54
55
55
<iframeheight='500'scrolling='no'title='Load Spatial Data Simple'src='//codepen.io/azuremaps/embed/yLNXrZx/?height=500&theme-id=0&default-tab=js,result&embed-version=2&editable=true'frameborder='no'allowtransparency='true'allowfullscreen='true'style='width: 100%;'>See the Pen <a href='https://codepen.io/azuremaps/pen/yLNXrZx/'>Load Spatial Data Simple</a> by Azure Maps (<a href='https://codepen.io/azuremaps'>@azuremaps</a>) on <a href='https://codepen.io'>CodePen</a>.
56
56
</iframe>
57
57
58
-
The next code demo shows how to read and load KML, or KMZ, to the map. KML can contain ground overlays, which will be in the form of an `ImageLyaer` or `OgcMapLayer`. These overlays must be added on the map separately from the features. Additionally, if the data set has custom icons, those icons need to be loaded in to the maps resources before the features are loaded.
58
+
The next code demo shows how to read and load KML, or KMZ, to the map. KML can contain ground overlays, which will be in the form of an `ImageLyaer` or `OgcMapLayer`. These overlays must be added on the map separately from the features. Additionally, if the data set has custom icons, those icons need to be loaded to the maps resources before the features are loaded.
59
59
60
60
<br/>
61
61
62
62
<iframeheight='500'scrolling='no'title='Load KML Onto Map'src='//codepen.io/azuremaps/embed/XWbgwxX/?height=500&theme-id=0&default-tab=js,result&embed-version=2&editable=true'frameborder='no'allowtransparency='true'allowfullscreen='true'style='width: 100%;'>See the Pen <a href='https://codepen.io/azuremaps/pen/XWbgwxX/'>Load KML Onto Map</a> by Azure Maps (<a href='https://codepen.io/azuremaps'>@azuremaps</a>) on <a href='https://codepen.io'>CodePen</a>.
63
63
</iframe>
64
64
65
-
You may optionally provide a proxy service for accessing cross domain assets that may not have CORs enabled. This snippet of code shows you could add the proxy service setting for the above code demo:
65
+
You may optionally provide a proxy service for accessing cross domain assets that may not have CORs enabled. This snippet of code shows you could provide a proxy service:
66
66
67
67
```javascript
68
68
@@ -71,7 +71,7 @@ var proxyServiceUrl = window.location.origin + '/CorsEnabledProxyService.ashx?ur
71
71
72
72
//Read a KML file from a URL or pass in a raw KML string.
The last code demo in this section shows how to read a delimited file and render it on the map. In this case, the code uses a CSV file that has spatial data columns.
84
+
The last demo below shows how to read a delimited file and render it on the map. In this case, the code uses a CSV file that has spatial data columns.
85
85
86
86
<br/>
87
87
@@ -90,9 +90,9 @@ The last code demo in this section shows how to read a delimited file and render
90
90
91
91
## Write spatial data
92
92
93
-
There are two main write functions in the spatial IO module. The `atlas.io.write` function generates a string, while the `atlas.io.writeCompressed` function generates a compressed zip file, which contains a text-based file with the spatial data in it. Both of these functions return a promise to add the feature to the file. Also, they both can write any of the following data: `SpatialDataSet`, `DataSource`, `ImageLayer`, `OgcMapLayer`, feature collection, feature, geometry, or an array of any combination of these data types. When writing using either functions, you can specify the desired file format. If the file format isn't specified, then the data will be written as KML.
93
+
There are two main write functions in the spatial IO module. The `atlas.io.write` function generates a string, while the `atlas.io.writeCompressed` function generates a compressed zip file. The compressed zip file would contain a text-based file with the spatial data in it. Both of these functions return a promise to add the data to the file. And, they both can write any of the following data: `SpatialDataSet`, `DataSource`, `ImageLayer`, `OgcMapLayer`, feature collection, feature, geometry, or an array of any combination of these data types. When writing using either functions, you can specify the wanted file format. If the file format isn't specified, then the data will be written as KML.
94
94
95
-
The following tool demonstrates the majority of the write options that can be used with the `atlas.io.write` function.
95
+
The tool below demonstrates the majority of the write options that can be used with the `atlas.io.write` function.
96
96
97
97
<br/>
98
98
@@ -101,14 +101,14 @@ The following tool demonstrates the majority of the write options that can be us
101
101
102
102
## Example of writing spatial data
103
103
104
-
The following sample allows you to drag and drop and then load spatial files onto the map. You can export GeoJSON data from the map and write it in one of the supported spatial data formats as a string or as a compressed file.
104
+
The following sample allows you to drag and drop and then load spatial files on the map. You can export GeoJSON data from the map and write it in one of the supported spatial data formats as a string or as a compressed file.
105
105
106
106
<br/>
107
107
108
108
<iframeheight='700'scrolling='no'title='Drag and drop spatial files onto map'src='//codepen.io/azuremaps/embed/zYGdGoO/?height=700&theme-id=0&default-tab=result&embed-version=2&editable=true'frameborder='no'allowtransparency='true'allowfullscreen='true'style='width: 100%;'>See the Pen <a href='https://codepen.io/azuremaps/pen/zYGdGoO/'>Drag and drop spatial files onto map</a> by Azure Maps (<a href='https://codepen.io/azuremaps'>@azuremaps</a>) on <a href='https://codepen.io'>CodePen</a>.
109
109
</iframe>
110
110
111
-
You may optionally provide a proxy service for accessing cross domain assets that may not have CORs enabled. This snippet of code shows you could incorporate a proxy service for the above code demo:
111
+
You may optionally provide a proxy service for accessing cross domain assets that may not have CORs enabled. This snippet of code shows you could incorporate a proxy service:
112
112
113
113
```javascript
114
114
@@ -120,6 +120,7 @@ function readData(data, fileName) {
120
120
fileCount++;
121
121
//Attempt to parse the file and add the shapes to the map.
122
122
atlas.io.read(data, {
123
+
//Provide a proxy service
123
124
proxyService: proxyServiceUrl
124
125
}).then(
125
126
//Success
@@ -132,7 +133,7 @@ function readData(data, fileName) {
132
133
133
134
## Read and write Well Known Text (WKT)
134
135
135
-
[Well Known Text](https://en.wikipedia.org/wiki/Well-known_text_representation_of_geometry), often referred to as WKT for short, is an Open Geospatial Consortium (OGC) standard for representing spatial geometries as text. Many geospatial systems support WKT such as Azure SQL and Azure PostgreSQL with the PostGIS plugin. Like most OGC standards, coordinates are formatted as "longitude latitude" to align with the "x y" convention. As an example, a point at longitude -110 and latitude 45 can be written as `POINT(-110 45)` using WKT format. The following table provides details on the geometry types supported for reading and writing WKT.
136
+
[Well Known Text](https://en.wikipedia.org/wiki/Well-known_text_representation_of_geometry) (WKT) is an Open Geospatial Consortium (OGC) standard for representing spatial geometries as text. Many geospatial systems support WKT, such as Azure SQL and Azure PostgreSQL using the PostGIS plugin. Like most OGC standards, coordinates are formatted as "longitude latitude" to align with the "x y" convention. As an example, a point at longitude -110 and latitude 45 can be written as `POINT(-110 45)` using the WKT format. The following table provides details on the geometry types supported for reading and writing WKT.
136
137
137
138
Well-known text can be read using the `atlas.io.ogc.WKT.read` function, and written using the `atlas.io.ogc.WKT.write` function.
138
139
@@ -156,10 +157,10 @@ The following code demonstrates reading and writing well-known text back and for
156
157
157
158
GML is a spatial XML file specification that's often used as an extension to other XML specifications. GeoJSON data can be written as XML with GML tags using the `atlas.io.core.GmlWriter.write` function. The XML that contains GML can be read using the `atlas.io.core.GmlReader.read` function. The read function has two options:
158
159
159
-
-`isAxisOrderLonLat` - The axis order of coordinates "latitude, longitude" or "longitude, latitude" can vary between data sets and isn't always welldefined. By default the GML reader reads the coordinate data as "latitude, longitude", but setting this option to true will read it as "longitude, latitude".
160
-
-`propertyTypes` - This option is a key value lookup table where the key is the name of a property in the data set and the value is the object type to cast the value to when parsing. The supported type values are: `string`, `number`, `boolean`, and `date`. If a property isn't in the look up table or the type not defined, it will be parsed as a string.
160
+
-The `isAxisOrderLonLat`option - The axis order of coordinates "latitude, longitude" or "longitude, latitude" can vary between data sets, and it isn't always well-defined. By default the GML reader reads the coordinate data as "latitude, longitude", but setting this option to true will read it as "longitude, latitude".
161
+
-The `propertyTypes`option - This option is a key value lookup table where the key is the name of a property in the data set. The value is the object type to cast the value to when parsing. The supported type values are: `string`, `number`, `boolean`, and `date`. If a property isn't in the look up table or the type isn't defined, the property will be parsed as a string.
161
162
162
-
The `atlas.io.read` function will attempt to fallback to the `atlas.io.core.GmlReader.read` function when it detects that the input data is XML, but the data isn't one of the other support spatial XML formats.
163
+
The `atlas.io.read` function will default to the `atlas.io.core.GmlReader.read` function when it detects that the input data is XML, but the data isn't one of the other support spatial XML formats.
0 commit comments