Main Content

geotable2table

Convert geospatial table to table

Since R2021b

Description

T = geotable2table(GT) converts the geospatial table GT to a table. The function replaces the objects in the Shape variable of GT with well-known text (WKT) string representations of geometry. The geospatial table and the table have the same dimensions.

T = geotable2table(GT,varnames) replaces the Shape variable with variables that have names specified by varnames.

example

Examples

collapse all

Convert a geospatial table to a table, then write the data to an Excel® spreadsheet file.

Import a shapefile containing the coordinates of world cities as a geospatial table.

GT = readgeotable("worldcities.shp");

Find the coordinate reference system type. The coordinate reference system type helps you determine appropriate variable names for the table.

GT.Shape.CoordinateSystemType
ans = 
"geographic"

Convert the geospatial table to a table. Replace the Shape variable with two variables containing coordinates by specifying the second argument as a two-element vector. The coordinate system is geographic, so use the variable names "Latitude" and "Longitude".

T = geotable2table(GT,["Latitude" "Longitude"]);

Write the table to an Excel spreadsheet file.

writetable(T,"worldcities.xlsx")

Import a shapefile containing a road network in Boston, MA, as a geospatial table. The Shape variable of the geospatial table contains maplineshape objects.

GT = readgeotable("boston_roads.shp");
class(GT.Shape)
ans = 
'maplineshape'

Convert the geospatial table to a table. The geotable2table function replaces the objects in the Shape variable with WKT string representations of geometry.

T = geotable2table(GT);

View the WKT string for the road called C STREET.

wkt = T.Shape(T.STREETNAME == "C STREET")
wkt = 
"LINESTRING (237527.171875 899661.1875,237343.875 899443.0625)"

Input Arguments

collapse all

Geospatial table. A geospatial table is a table or timetable object with a Shape variable that contains geopointshape, geolineshape, geopolyshape, mappointshape, maplineshape, or mappolyshape objects. The Shape variable must be the first variable.

For more information about geospatial tables, see Create Geospatial Tables.

Data Types: table

Table variable names used to replace the Shape variable of the geospatial table, specified as a string scalar or two-element string vector.

  • To replace the shape objects in the Shape variable with WKT string representations of geometry, specify varnames as a string scalar, such as "WKTStrings". Unlike shape objects, WKT string representations of geometry do not contain information about the coordinate reference system.

  • To replace the Shape variable with two table variables containing latitude and longitude coordinates or x- and y-coordinates, specify varnames as a two-element string vector, such as ["Latitude" "Longitude"].

The geotable2table function does not project or unproject coordinates. For more information about projecting or unprojecting coordinates, see projfwd or projinv.

Data Types: string

Output Arguments

collapse all

Output table, returned as a table or timetable object.

  • When you specify varnames as a string scalar, the output table contains WKT string representations of geometry.

  • When you specify varnames as a two-element string vector, the output table contains latitude-longitude or x- y coordinates. If a table row represents an individual point, then the coordinates are returned as numeric scalars. Otherwise, the coordinates are returned as cell arrays of numeric vectors.

Data Types: table

Version History

Introduced in R2021b