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
3. Because the creation of geometric objects is done by giving the constructor in text form. The commands for adding objects to table will take the form:
4. To check the definition of graphical objects in the database, we can use the function *ST_AsText*:
175
+
```sql
176
+
SELECT object_name, ST_AsText(geom) FROM geom_example;
177
+
```
178
+
179
+
## Spatial function
180
+
Using geometric objects in the spatial database is done by manipulating them with the functions built into the database. We should remember that with PostGIS all functions assume the geometric type, but their operation differs depending on the represented object. Of course, this principle does not apply to other database engines of this type.
181
+
182
+
In this section, selected functions will be discussed along with their subcategories.
183
+
184
+
### Input/Output data
185
+
-**ST_GeomFromText(text)** - returns geometry,
186
+
-**ST_AsText(geometry)** - returns WKT text,
187
+
-**ST_AsEWKT(geometry)** - returns EWKT text,
188
+
-**ST_GeomFromWKB(bytea)** - returns geometry,
189
+
-**ST_AsBinary(geometry)** - returns WKB bytea,
190
+
-**ST_AsEWKB(geometry)** - returns EWKB bytea,
191
+
-**ST_GeomFromGML(text)** - returns geometry,
192
+
-**ST_AsGML(geometry)** - returns GML text,
193
+
-**ST_GeomFromKML(text)** - returns geometry,
194
+
-**ST_AsKML(geometry)** - returns KML text,
195
+
-**ST_AsGeoJSON(geometry)** - returns JSON text,
196
+
-**ST_AsSVG(geometry)** - returns SVG text,
197
+
198
+
### Data type exploration
199
+
200
+
-**ST_GeometryType(geometry)** - returns the type of the geometry,
201
+
-**ST_NDims(geometry)** - returns the number of dimensions of the geometry,
202
+
-**ST_NumGeometries(geometry)** - returns the number of parts in the collection,
203
+
-**ST_GeometryN(geometry,int)** - returns the specified part of the collection,
204
+
-**ST_NumGeometries(multi/geomcollection)** - returns the number of parts in the collection
205
+
206
+
### Geometry description
207
+
-**ST_X(geometry)** - returns the X coordinate of point,
208
+
-**ST_Y(geometry)** - returns the Y coordinate of point,
209
+
-**ST_StartPoint(geometry)** - returns the first line string coordinate as a point,
210
+
-**ST_EndPoint(geometry)** - returns the last line string coordinate as a point,
211
+
-**ST_NPoints(geometry)** - returns the number of coordinates in the line string,
212
+
-**ST_Length(geometry)** - returns the total length of all linear parts,
213
+
-**ST_Area(geometry)** - returns the total area of all polygonal parts,
214
+
-**ST_NRings(geometry)** - returns the number of rings (usually 1, more if there are holes) of polygonal,
215
+
-**ST_ExteriorRing(geometry)** - returns the outer ring as a line string of polygonal,
216
+
-**ST_InteriorRingN(geometry,n)** - returns a specified interior ring as a line string of polygonal,
217
+
-**ST_Perimeter(geometry)** - returns the length of all the rings of polygonal,
218
+
219
+
### Geometry relation
220
+
-**ST_Contains(geometry A, geometry B)** - returns true if geometry A contains geometry B
221
+
-**ST_Crosses(geometry A, geometry B)** - returns true if geometry A crosses geometry B
222
+
-**ST_Disjoint(geometry A , geometry B)** - returns true if the geometries do not “spatially intersect”
223
+
-**ST_Distance(geometry A, geometry B)** - returns the minimum distance between geometry A and geometry B
224
+
-**ST_DWithin(geometry A, geometry B, radius)** - returns true if geometry A is radius distance or less from geometry B
225
+
-**ST_Equals(geometry A, geometry B)** - returns true if geometry A is the same as geometry B
226
+
-**ST_Intersects(geometry A, geometry B)** - returns true if geometry A intersects geometry B
227
+
-**ST_Overlaps(geometry A, geometry B)** - returns true if geometry A and geometry B share space, but are not completely contained by each other.
228
+
-**ST_Touches(geometry A, geometry B)** - returns true if the boundary of geometry A touches geometry B
229
+
-**ST_Within(geometry A, geometry B)** - returns true if geometry A is within geometry B
230
+
127
231
##Exercises:
128
232
129
233
1. How many records are in the nyc_streets table?
130
234
2. How many streets in New York have names that start with ‘B’, 'Q' and 'M'?
131
235
3. What is the population of New York city?
132
236
4. What is the population of the Bronx, Manhattan and Queens?
133
237
5. How many "neighborhoods" are in each borough?
238
+
6. What is the area of the: West Village, Harlem, Great Kills neighborhood?
239
+
7. Find all neighborhoods bordering on: Rossville, Queens Village and Midtown
240
+
8. What is the area of: Staten Island, Manhattan, Brooklyn?
241
+
9. How many census blocks in New York City have a hole in them?
242
+
10. What is the summary area of 'a hole' of census blocks in New York City?
243
+
11. What is the length of streets in New York City, summarized by type?
244
+
12. What streets crossing with: Pacific St, E 9th St, Avenue K?
245
+
13. Find ten closest stations from: Elder Ave, Castle Hill Ave, 4th Ave.
0 commit comments