rgeo 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- data/History.rdoc +5 -0
- data/Spatial_Programming_With_RGeo.rdoc +36 -31
- data/Version +1 -1
- data/lib/rgeo/cartesian/bounding_box.rb +2 -2
- data/lib/rgeo/cartesian/calculations.rb +35 -8
- data/lib/rgeo/cartesian/interface.rb +6 -6
- data/lib/rgeo/coord_sys/cs/entities.rb +1 -1
- data/lib/rgeo/coord_sys/proj4.rb +1 -1
- data/lib/rgeo/coord_sys/srs_database/active_record_table.rb +12 -12
- data/lib/rgeo/coord_sys/srs_database/interface.rb +5 -5
- data/lib/rgeo/coord_sys/srs_database/proj4_data.rb +3 -3
- data/lib/rgeo/coord_sys/srs_database/sr_org.rb +1 -1
- data/lib/rgeo/coord_sys/srs_database/url_reader.rb +1 -1
- data/lib/rgeo/feature/factory.rb +7 -7
- data/lib/rgeo/feature/factory_generator.rb +7 -7
- data/lib/rgeo/feature/geometry.rb +11 -12
- data/lib/rgeo/feature/line_string.rb +1 -1
- data/lib/rgeo/feature/types.rb +5 -5
- data/lib/rgeo/geographic/interface.rb +18 -18
- data/lib/rgeo/geographic/simple_mercator_projector.rb +11 -3
- data/lib/rgeo/geos/interface.rb +8 -8
- data/lib/rgeo/wkrep/wkb_generator.rb +4 -4
- data/lib/rgeo/wkrep/wkb_parser.rb +4 -4
- data/lib/rgeo/wkrep/wkt_generator.rb +4 -4
- data/lib/rgeo/wkrep/wkt_parser.rb +5 -5
- data/test/simple_cartesian/tc_calculations.rb +7 -0
- metadata +4 -14
data/History.rdoc
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
=== 0.2.5 / 2011-03-21
|
2
|
+
|
3
|
+
* Line segment intersection tests in the simple cartesian implementations were failing for a few cases involving collinear segments. Fixed. (Reported by Dimitry Solovyov.)
|
4
|
+
* Argument hash RDocs should be more readable.
|
5
|
+
|
1
6
|
=== 0.2.4 / 2010-12-31
|
2
7
|
|
3
8
|
* Several bugs were preventing the low-level Proj4 transform functions from working at all. Fixed. (Reported by mRg.)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
= An Introduction to Spatial Programming With RGeo
|
2
2
|
|
3
3
|
* by Daniel Azuma
|
4
|
-
* version 0.
|
4
|
+
* version 0.3 (17 Feb 2011)
|
5
5
|
|
6
6
|
== Introduction
|
7
7
|
|
@@ -18,7 +18,7 @@ The contents of this document are as follows.
|
|
18
18
|
* Section 5 covers the most common open source spatial databases.
|
19
19
|
* Section 6 briefly covers interoperability with location services and other externally-sourced geospatial data.
|
20
20
|
|
21
|
-
Geographic information systems (GIS) is a broad and highly sophisticated field, and this introduction will only scratch the surface of the current state of the art. The goal is not to be comprehensive, but to summarize the important elements, and reference outside resources for readers
|
21
|
+
Geographic information systems (GIS) is a broad and highly sophisticated field, and this introduction will only scratch the surface of the current state of the art. The goal is not to be comprehensive, but to summarize the important elements, and reference outside resources for readers seeking more detailed information.
|
22
22
|
|
23
23
|
=== About The Author
|
24
24
|
|
@@ -28,9 +28,9 @@ Geographic information systems (GIS) is a broad and highly sophisticated field,
|
|
28
28
|
|
29
29
|
=== 1.1. Why Spatial Programming?
|
30
30
|
|
31
|
-
By 2010, location had established itself as one of the hottest emerging technological trends. In January, a Juniper Research report predicted that mobile location services alone could drive revenues of nearly $13 billion by 2014 (see {TechCrunch article}[http://techcrunch.com/2010/02/23/location-based-services-revenue/]), while location dominated new feature offerings from startups
|
31
|
+
By 2010, location had established itself as one of the hottest emerging technological trends. In January, a Juniper Research report predicted that mobile location services alone could drive revenues of nearly $13 billion by 2014 (see {TechCrunch article}[http://techcrunch.com/2010/02/23/location-based-services-revenue/]), while location dominated new feature offerings from a myriad of startups as well as from giants such as Facebook and Twitter. Although the underlying disciplines of computer-assisted cartography and geographic information systems (GIS) have been around for several decades, they have broken into mainstream consumer technology only very recently. This has largely been due to a few key developments, notably, the success of online mapping applications beginning with Google Maps, and the ubiquity of mobile GPS devices especially in mobile phones.
|
32
32
|
|
33
|
-
Despite this growing interest, location-aware applications remain difficult to develop because the concepts and techniques involved are only beginning to make their way into the mainstream developer consciousness and tools.
|
33
|
+
Despite this growing interest, location-aware applications remain difficult to develop because the concepts and techniques involved are only beginning to make their way into the mainstream developer consciousness and tools. The primary purpose of this document is to cover the basics that a Ruby or Ruby On Rails developer needs to know when developing with location data, and to introduce the tools and resources that are available.
|
34
34
|
|
35
35
|
=== 1.2. The Emerging Spatial Ecosystem
|
36
36
|
|
@@ -40,7 +40,7 @@ Visualization tools have advanced considerably in recent years. Mapping services
|
|
40
40
|
|
41
41
|
Most major relational databases now support spatial extensions. The {MySQL}[http://mysql.com/] database provides basic spatial column support out of the box. Third-party add-on libraries exist for {Sqlite3}[http://www.sqlite.org/] and {PostgreSQL}[http://www.postgresql.org/] in the form of {SpatiaLite}[http://www.gaia-gis.it/spatialite/] and {PostGIS}[http://www.postgis.org/], respectively. Commercial databases such as Oracle and Microsoft SQL Server also provide facilities for storing and querying spatial data. Spatial features are also appearing in non-relational data stores. {MongoDB}[http://www.mongodb.org/] recently introduced geospatial indexing, {Solr}[http://lucene.apache.org/solr/] is expected to support spatial queries in the next release of its Lucene-based search engine, and {Sphinx}[http://sphinxsearch.com/] also provides limited spatial search capabilities.
|
42
42
|
|
43
|
-
A variety of data services have also appeared. Geocoding, the process approximating a latitude/longitude coordinate from a street address, is now offered by most major mapping service vendors such as {Google}[http://code.google.com/apis/maps/documentation/geocoding/], {Microsoft}[http://www.microsoft.com/maps/developers/], and {Yahoo}[http://developer.yahoo.com/geo/placefinder/]. Place databases with geocoded business and major location listings are now also available from a variety of vendors. {SimpleGeo}[http://www.simplegeo.com/]
|
43
|
+
A variety of data services have also appeared. Geocoding, the process approximating a latitude/longitude coordinate from a street address, is now offered by most major mapping service vendors such as {Google}[http://code.google.com/apis/maps/documentation/geocoding/], {Microsoft}[http://www.microsoft.com/maps/developers/], and {Yahoo}[http://developer.yahoo.com/geo/placefinder/]. Place databases with geocoded business and major location listings are now also available from a variety of vendors. Several services, notably {SimpleGeo}[http://www.simplegeo.com/], have recently appeared for cloud-based storage and querying of custom location data.
|
44
44
|
|
45
45
|
Integrating these existing services in a web application is often a challenge, but a few integration libraries and frameworks do exist. {GeoDjango}[http://geodjango.org/] is an add-on for the Python-based Django web framework for building location-based applications. {RGeo}[http://github.com/dazuma/rgeo] is a suite of libraries for Ruby that can perform the same function for Ruby on Rails.
|
46
46
|
|
@@ -50,7 +50,7 @@ Perhaps most important of all, however, are the organizations that have appeared
|
|
50
50
|
|
51
51
|
Ruby developers have had access to a fair number of spatial tools, primarily integration libraries for external services. {Geokit}[http://geokit.rubyforge.org/] provides a common interface for querying geocoding services, and a basic ActiveRecord extension for simple spatial queries. {YM4R}[http://ym4r.rubyforge.org/] provides a simple interface for integrating the Google and Yahoo map visualization tools in a Ruby application. Finally, {GeoRuby}[http://georuby.rubyforge.org/] provides classes for basic spatial data types such as points, lines, and polygons, and the add-on library {spatial_adapter}[http://github.com/fragility/spatial_adapter] hacks a few of the popular ActiveRecord database adapters to support spatial columns in the database.
|
52
52
|
|
53
|
-
In this document, we will
|
53
|
+
In this document, we will cover {RGeo}[http://github.com/dazuma/rgeo], a new spatial data library for Ruby that provides a complete and robust implementation of the standard OGC spatial data types and operations. It covers some of the same functionality as GeoRuby and spatial_adapter. However, where GeoRuby implements only a minimal subset of the OGC feature interfaces, \RGeo supports the entire specification, as well as providing many features and extensions not available with the older libraries.
|
54
54
|
|
55
55
|
\RGeo comprises several libraries, distributed as gems: a core library, and a suite of optional add-on modules. The core library, distributed as the {rgeo}[http://github.com/dazuma/rgeo] gem, includes the spatial data implementation itself. Currently available add-on modules include {rgeo-geojson}[http://github.com/dazuma/rgeo-geojson], which reads and writes the {GeoJSON}[http://www.geojson.org/] format, and {rgeo-shapefile}[http://github.com/dazuma/rgeo-shapefile], which reads ESRI shapefiles. A number of ActiveRecord adapters also utilize \RGeo to communicate with spatial databases; these include {mysqlspatial}[http://github.com/dazuma/activerecord-mysqlspatial-adapter], {mysql2spatial}[http://github.com/dazuma/activerecord-mysql2spatial-adapter], {spatialite}[http://github.com/dazuma/activerecord-spatialite-adapter], and {postgis}[http://github.com/dazuma/activerecord-postgis-adapter].
|
56
56
|
|
@@ -60,7 +60,7 @@ This section will cover the standard types of spatial data used in geospatial ap
|
|
60
60
|
|
61
61
|
=== 2.1. The Simple Features Specification
|
62
62
|
|
63
|
-
The Open Geospatial Consortium (OGC) defines and publishes a specification entitled "{Geographic information -- Simple feature access}[http://www.opengeospatial.org/standards/sfa]", which defines, among other things, a set of spatial data types and operations that can be done on them. This standard, which we will refer to as the Simple Features Specification (SFS), defines the core interfaces used by most spatial applications and databases. Although more recent versions of the spec are now available, most current implementations, including \RGeo, follow version 1.1 of the SFS, and this is the specification we will cover here.
|
63
|
+
The Open Geospatial Consortium (OGC) defines and publishes a specification entitled "{Geographic information -- Simple feature access}[http://www.opengeospatial.org/standards/sfa]", which defines, among other things, a set of spatial data types and operations that can be done on them. This standard, which we will refer to as the Simple Features Specification (SFS), defines the core types and interfaces used by most spatial applications and databases. Although more recent versions of the spec are now available, most current implementations, including \RGeo, follow version 1.1 of the SFS, and this is the specification we will cover here.
|
64
64
|
|
65
65
|
A "feature" in the SFS is a geometric object in 2 or 3 dimensional space. These objects can be points, lines, curves, surfaces, and polygons-- in general, most 0, 1, or 2 dimensional objects are supported. Each of these objects is identified by coordinates (X, Y, and sometimes Z), and has an object-oriented interface associated with it, defining a set of operations that can be done. In \RGeo, these interfaces exist as modules in the RGeo::Feature namespace.
|
66
66
|
|
@@ -80,7 +80,7 @@ An SFS "Point" is a single 0-dimensional point in space. Points are typically us
|
|
80
80
|
|
81
81
|
An SFS "LineString" is a set of one or more connected line segments representing a single continuous, piecewise linear path. It could, for example, represent the path of a single street, the full driving directions from one point to another, or the path of a waterway. It is defined by connecting a series of points in order with line segments, and you can retrieve those points from the LineString object.
|
82
82
|
|
83
|
-
LineString itself has two subclases, Line and LinearRing. Line is restricted to a single line segment (i.e. two points). LinearRing is a "closed" LineString,
|
83
|
+
LineString itself has two subclases, Line and LinearRing. Line is restricted to a single line segment (i.e. two points). LinearRing is a "closed" LineString, in which the two endpoints are coincident.
|
84
84
|
|
85
85
|
(LineString is actually a subclass of the more general abstract class "Curve", which need not be piecewise linear. However, Curve is not by itself instantiable, and the current SFS version does not actually specify another type of instantiable Curve that is not a LineString.)
|
86
86
|
|
@@ -114,9 +114,9 @@ For complete details on the geometry class hierarchy, download the actual {Simpl
|
|
114
114
|
|
115
115
|
=== 2.10. \RGeo Geometry Factories
|
116
116
|
|
117
|
-
The data types we have covered here are actually merely interface specifications. \RGeo
|
117
|
+
The data types we have covered here are actually merely interface specifications. \RGeo provides several different concrete implementations of these data type interfaces, intended for different use cases. For example, the RGeo::Geos implementation is \RGeo's main implementation which provides every data type and every operation defined by the SFS. However, that implementation requires a third-party C library, GEOS, to be installed. In cases where that library is not available, \RGeo provides an alternative, the Simple Cartesian implementation, which is a pure Ruby implementation that provides every data type but does not implement some of the more advanced geometric operations. \RGeo also provides further implementations that are designed specifically to work with geographic (longitude/latitude) coordinates, and different projections and ways of performing calculations on the earth's surface. These different implementations are described in more detail in the section on Coordinate Systems and Projections.
|
118
118
|
|
119
|
-
|
119
|
+
Each concrete implementation is represented in \RGeo by a factory. A factory is an object that represents the coordinate system and other settings for that implementation. It also provides methods for creating actual geometric objects for that implementation, as defined in the RGeo::Feature::Factory interface. For example:
|
120
120
|
|
121
121
|
factory = get_my_factory()
|
122
122
|
point1 = factory.point(1, 2)
|
@@ -168,7 +168,7 @@ A second common property of geometry objects is "simplicity", which basically me
|
|
168
168
|
|
169
169
|
All geometry objects also contain a "spatial reference ID", returned by the <tt>Geometry#srid</tt> method. This is an external ID reference indicating the "spatial reference system", or coordinate system in use by the geometry. See the section on Coordinate Systems and Projections for further discussion.
|
170
170
|
|
171
|
-
=== 3.2.
|
171
|
+
=== 3.2. Relational Operations
|
172
172
|
|
173
173
|
The SFS specifies a suite of comparison operations that test geometric objects for such relational predicates as equality, overlap, containment, and so forth. In \RGeo, these operations are implemented by methods that return booleans. e.g.
|
174
174
|
|
@@ -204,7 +204,7 @@ Similarly, \RGeo's equality checking comes in several forms: geometric equality,
|
|
204
204
|
p1.equals?(p2) # => false
|
205
205
|
p1.equals?(p1) # => true
|
206
206
|
|
207
|
-
=== 3.3.
|
207
|
+
=== 3.3. Binary Spatial Operations
|
208
208
|
|
209
209
|
The SFS also provides several operations that take two geometries and yield a third. For example, you can calculate the intersection, union, or difference between two geometries. In addition to the methods specified by the SFS interfaces, \RGeo provides operators for some of these calculations.
|
210
210
|
|
@@ -216,7 +216,7 @@ The SFS also provides several operations that take two geometries and yield a th
|
|
216
216
|
diff = p1.difference(p2) # or p1 - p2
|
217
217
|
diff.is_empty? # returns true
|
218
218
|
|
219
|
-
=== 3.4.
|
219
|
+
=== 3.4. Unary Spatial Operations
|
220
220
|
|
221
221
|
Methods are provided to compute the boundary of an object, the envelope (i.e. the bounding box), and the convex hull. In addition, there is a "buffer" method that attempts to return a polygon approximating the area within a given distance from the object. Note that, because the SFS does not yet define any geometric types with curved edges, most buffers will be polygonal approximations.
|
222
222
|
|
@@ -255,11 +255,11 @@ Note that there are several key shortcomings in the WKT and WKB formats as stric
|
|
255
255
|
|
256
256
|
So far, we have discussed geometric data and operations mostly without reference to coordinate system. However, coordinate system is a critical component for interpreting what a piece of data means. If you have a point (1, 2), are the 1 and 2 measured in meters? Miles? Degrees? And where are they measured from? What is the origin (0, 0), and what directions do X and Y represent?
|
257
257
|
|
258
|
-
Generally, the spatial technologies we're discussing are used to represent location, objects on the
|
258
|
+
Generally, the spatial technologies we're discussing are used to represent location, objects on the earth's surface. In this section, we'll cover the coordinate systems that you'll use for geolocation, as well as the issues you'll face.
|
259
259
|
|
260
260
|
=== 4.1. The World is Not Flat
|
261
261
|
|
262
|
-
First off, most of us agree that the earth is not flat, but
|
262
|
+
First off, most of us agree that the earth is not flat, but has a shape resembling a slightly flattened ball. This immediately results in a whole host of complications when dealing with geometric objects on the earth's surface. Distance can't quite be computed accurately using the familiar formulas you learned in high school geometry. Lines that start off parallel will eventually cross. And if you try to display things on a flat computer monitor, you will end up with various kinds of distortion.
|
263
263
|
|
264
264
|
Let's take a simple example. Suppose we have a simple LineString with two points: starting in Vancouver, Canada, and ending in Frankfurt, Germany, both located at around 50 degrees north latitude. The LineString would consist of a straight line between those two points. But what is meant by "straight"? Does the shape follow the 50 degrees north latitude line, passing through Newfoundland? Or does it follow the actual shortest path on the globe, which passes much further north, close to Reykjavik, Iceland? (For a detailed explanation, see Morten Nielsen's post {"Straight Lines on a Sphere"}[http://www.sharpgis.net/post/2008/01/12/Straight-lines-on-a-sphere.aspx], which also includes some helpful diagrams.) If you were to call the SFS "distance" function to measure the distance between this LineString and a Point located at Reykjavik, what would you get?
|
265
265
|
|
@@ -289,7 +289,7 @@ Does this matter in your application? The answer is, it depends: on what kind of
|
|
289
289
|
|
290
290
|
=== 4.3. Geodetic and Projection Parameters
|
291
291
|
|
292
|
-
This subsection covers some more advanced topics that most developers may not need to deal with directly, but I believe it is important to have at least a
|
292
|
+
This subsection covers some more advanced topics that most developers may not need to deal with directly, but I believe it is important to have at least a high-level understanding of them.
|
293
293
|
|
294
294
|
Simply put, there's more to a coordinate system than just the type: geocentric, geographic, or projected. For a geocentric coordinate system, we know it's centered at the center of the earth, but where _is_ the center of the earth? Which direction do the axes point? And do we measure the units in meters, miles, or light-years? For a geographic coordinate system, again, we need a center and orientation (i.e. where is the "zero longitude" line?), but we also need to define specifically _which_ "latitude". The latitude commonly used is the "geodetic latitude", which is the angle between the equator and what is normal (i.e. vertical) to the surface of the earth. This means it is dependent on one's model of the earth's surface, whether you use a sphere or a flattened ellipsoid, and how much flattening you choose. The same location on the earth's surface may have different latitudes depending on which system you use! As for projected systems, not only do we need to specify which projection to use (and there are hundreds defined), but we also need to know which geographic (latitude-longitude) system to start from. That is, a map projection is merely a function mapping latitude/longitude to flat coordinates, so we need to specify _which_ latitude/longitude.
|
295
295
|
|
@@ -311,7 +311,7 @@ What about Google and Bing maps? They use a combination of two coordinate system
|
|
311
311
|
|
312
312
|
=== 4.4. Using Proj4
|
313
313
|
|
314
|
-
Under most circumstances, when you're working with geographic data in \RGeo, you can probably use either the spherical factory (if you just want to deal with points on the sphere) or the simple mercator factory (if you want to deal with objects as they would appear on Google or Bing maps). However, if you need to work with arbitrary projections,
|
314
|
+
Under most circumstances, when you're working with geographic data in \RGeo, you can probably use either the spherical factory (if you just want to deal with points on the sphere) or the simple mercator factory (if you want to deal with objects as they would appear on Google or Bing maps). However, if you need to work with arbitrary projections, you can use {Proj}[http://trac.osgeo.org/proj/], a C library that understands coordinate systems and handles the math involved. Proj defines a syntax for specifying coordinate systems based on the above parameters, and provides an implementation for transforming coordinates from one coordinate system to another. Its syntax has become a <i>de facto</i> standard.
|
315
315
|
|
316
316
|
\RGeo provides a Ruby wrapper around the Proj interface, and integrates proj into its representation of geometric objects. You can use the Proj syntax to specify the coordinate system for input data, and tell \RGeo to translate it to a different coordinate system for analysis or output. \RGeo's geographic factories can also be configured with a particular projection using the Proj syntax, and automatically convert between latitude-longitude and that projection's coordinate system. For example:
|
317
317
|
|
@@ -329,29 +329,31 @@ Under most circumstances, when you're working with geographic data in \RGeo, you
|
|
329
329
|
|
330
330
|
=== 4.5. Spatial Reference Systems and the EPSG Dataset
|
331
331
|
|
332
|
-
The OGC also defines a syntax for specifying coordinate systems, the {Coordinate Transformation Services Specification}[http://www.opengeospatial.org/standards/ct]. This specification defines both an object model and a well-known text representation for coordinate systems and transformations. \RGeo
|
332
|
+
The OGC also defines a syntax for specifying coordinate systems, the {Coordinate Transformation Services Specification}[http://www.opengeospatial.org/standards/ct]. This specification defines both an object model and a well-known text representation for coordinate systems and transformations. \RGeo also provides basic support for this specification; you can attach an OGC coordinate system specification to a factory to indicate the coordinate system. However, if you want \RGeo to automatically convert spatial data between coordinate systems, you must use Proj4 syntax.
|
333
333
|
|
334
334
|
Finally, there also exists a <i>de facto</i> standard database of coordinate systems and related parameters, published by EPSG (now the OGP Geomatics Committee). This is a set of coordinate systems, each tagged with a well-known ID number, including geographic and projected systems. You can browse this database, including both OGC and Proj4 representations, at http://www.spatialreference.org/. This database is also included as a table in many popular spatial databases including PostGIS and SpatiaLite. Typically, the EPSG number is used as the SRID identifying the coordinate system for geometric objects stored in the database.
|
335
335
|
|
336
336
|
The most common EPSG number in use is 4326, which identifies the WGS84 geographic (longitude-latitude) coordinate system on the WGS84 ellipsoid. In fact, current versions of PostGIS restrict geography objects to this SRID. Be aware, again, that this is a non-projected ellipsoidal coordinate system. If you load EPSG 4326 data directly into, say, a Cartesian implementation in \RGeo, then the basic data fields will work fine, but size and distance functions, as well as spatial analysis operations such as intersections, may yield surprising or incorrect results because the data's coordinate system does not match how \RGeo is treating it.
|
337
337
|
|
338
|
+
The EPSG database is so ubiquitous that it is commonly distributed along with spatial database systems such as PostGIS and SpatiaLite, as described in the next section. \RGeo takes advantage of this by providing automatic lookup of the coordinate system from the EPSG number. If you use one of these spatial databases, you do not need to know the exact definition of the coordinate system; just provide the EPSG number in the SRID field, and the \RGeo factory will know how to construct the correct Proj4 syntax for performing coordinate conversions. You can even create custom spatial reference system databases if you do not want to use the provided standard databases.
|
339
|
+
|
338
340
|
== 5. Spatial Databases
|
339
341
|
|
340
342
|
Now that we have a basic understanding of geospatial data, we'll turn to the question of storing and querying for this data.
|
341
343
|
|
342
|
-
As we have seen, there exist a variety of ways to serialize geometric objects, notably the OGC "well-known text" and "well-known binary" formats. The simplest way to store such objects in a database, then, is to simply serialize the object into a blob. However, this would not allow us to
|
344
|
+
As we have seen, there exist a variety of ways to serialize geometric objects, notably the OGC "well-known text" and "well-known binary" formats. The simplest way to store such objects in a database, then, is to simply serialize the object into a blob. However, this would not allow us to perform queries with conditions relating to the object itself. Typical location-based applications may need to run queries such as "give me all the locations within one mile of a particular position." This kind of capability is the domain of spatial databases.
|
343
345
|
|
344
|
-
=== 5.1. Spatial Queries and Indexes
|
346
|
+
=== 5.1. Spatial Queries and Spatial Indexes
|
345
347
|
|
346
348
|
The OGC defines a {specification}[http://www.opengeospatial.org/standards/sfs], related to the SFS, describing SQL extensions for a spatial database. This specification includes a table for spatial reference systems (that is, coordinate systems) which can contain OGC and Proj4 representations, and a table of metadata for geometry columns which stores such information as type, dimension, and srid constraints. It also defines a suite of SQL functions that you can call in a query. For example, in a compliant database, to find all rows in "mytable" where the geometry-valued column "geom" contains data within 5 units of the coordinates (10, 20), you might be able to run a query similar to:
|
347
349
|
|
348
350
|
SELECT * FROM mytable WHERE ST_Distance(geom, ST_WKTToSQL("POINT(10 20)")) > 5;
|
349
351
|
|
350
|
-
Like all database queries, however, when there are a large number of rows, such
|
352
|
+
Like all database queries, however, when there are a large number of rows, such a query can be slow if it has to do a full table scan. This is especially true if it has to evaluate geometric functions like the above, which can be numerically complex and slow to execute. To speed up queries, it is necessary to index your spatial columns.
|
351
353
|
|
352
|
-
Spatial indexes are somewhat more complex than typical database indexes. A typical B-tree index relies on a global ordering of data: the fact that you can sort values in a binary tree and hence perform logarithmic-time searches. However, there isn't an obvious global ordering for spatial data. Should POINT(0 1) come before or after POINT(1 0)? And how do each of those compare with LINESTRING(0 1, 1 0)? More concretely, spatial data exists in two dimensions rather than one, and can span finite ranges.
|
354
|
+
Spatial indexes are somewhat more complex than typical database indexes. A typical B-tree index relies on a global ordering of data: the fact that you can sort scalar values in a binary tree and hence perform logarithmic-time searches. However, there isn't an obvious global ordering for spatial data. Should POINT(0 1) come before or after POINT(1 0)? And how do each of those compare with LINESTRING(0 1, 1 0)? More concretely, spatial data exists in two dimensions rather than one, and can span finite ranges.
|
353
355
|
|
354
|
-
Spatial databases handle the problem of indexing spatial data in
|
356
|
+
Spatial databases handle the problem of indexing spatial data in various ways, but most techniques are variants on an indexing algorithm known as an R-tree. I won't go into the details of how an R-tree works here. For the interested, I recommend the text {"Spatial Databases With Application To GIS"}[http://www.amazon.com/dp/1558605886], which covers a wide variety of issues related to basic spatial database implementation. For our purposes, just note that for large datasets, it is necessary to index the geometry columns, and that the index creation process may be different from that of normal scalar columns. The next sections provide some information specific to some of the common spatial databases.
|
355
357
|
|
356
358
|
=== 5.2. MySQL Spatial
|
357
359
|
|
@@ -370,7 +372,7 @@ In general, if you're using MySQL for the rest of your application, and you just
|
|
370
372
|
|
371
373
|
{SpatiaLite}[http://www.gaia-gis.it/spatialite/] is an add-on library for the popular database {Sqlite}[http://www.sqlite.org/]. It is close to a fully compliant implementation of the OGC SQL specification, but as a result it is more difficult to manage than MySQL.
|
372
374
|
|
373
|
-
To install SpatiaLite, you must compile it as a shared library, then load that library as an extension using the appropriate sqlite API. This gives you access to the full suite of spatial SQL functions defined by the OGC, along with a set of utility functions for managing spatial columns and indexes as well as the geometry columns and spatial reference systems tables. These utility functions automatically create and manage the appropriate entries in the geometry columns table
|
375
|
+
To install SpatiaLite, you must compile it as a shared library, then load that library as an extension using the appropriate sqlite API. This gives you access to the full suite of spatial SQL functions defined by the OGC, along with a set of utility functions for managing spatial columns and indexes as well as the geometry columns and spatial reference systems tables. These utility functions automatically create and manage the appropriate entries in the geometry columns table and the triggers that enforce type and SRID constraints and maintain the spatial indexes.
|
374
376
|
|
375
377
|
CREATE TABLE mytable(id INTEGER PRIMARY KEY);
|
376
378
|
SELECT AddGeometryColumn('mytable', 'latlon', 4326, 'POINT', 'XY');
|
@@ -382,7 +384,7 @@ Spatial indexes themselves are implemented using SpatiaLite's Rtree extension, a
|
|
382
384
|
(SELECT pkid FROM idx_mytable_latlon WHERE
|
383
385
|
xmin > -123 AND xmax < -122 AND ymin > 47 AND ymax < 48);
|
384
386
|
|
385
|
-
SpatiaLite's internal format is a binary format loosely based on the WKB, but extended to include the SRID, as well as some internal bounding rectangle data to speed up calculations. Like MySQL, SpatiaLite provides functions to convert this data to and from WKB and WKT. I'm not completely clear on this, but it does not seem that SpatiaLite supports Z and M coordinates.
|
387
|
+
SpatiaLite's internal format is a binary format loosely based on the WKB, but extended to include the SRID, as well as some internal bounding rectangle data to speed up calculations. Like MySQL, SpatiaLite provides functions to convert this data to and from WKB and WKT. I'm not completely clear on this, but it does not seem that SpatiaLite supports Z and M coordinates at this time.
|
386
388
|
|
387
389
|
=== 5.4. PostGIS
|
388
390
|
|
@@ -394,16 +396,18 @@ Like SpatiaLite, PostGIS is compiled and installed as a plug-in library to the d
|
|
394
396
|
SELECT AddGeometryColumn('mytable', 'latlon', 4326, 'POINTM', 3);
|
395
397
|
CREATE INDEX idx_mytable_latlon ON mytable USING GIST (latlon);
|
396
398
|
|
399
|
+
PostGIS actually provides two types of spatial columns: geometry and geography. The former assumes a flat coordinate system and performs Euclidean/Cartesian geometric calculations using any EPSG coordinate system you choose. The latter is specifically designed for geographic (longitude-latitude) coordinate systems. It performs calculations on the sphereoid and only works with EPSG 4326; however, some of the more advanced functions are not implemented because the calculations involved would be prohibitively complex. When you create a spatial column in PostGIS, you will need to decide whether to use the geometry or geography type.
|
400
|
+
|
397
401
|
PostGIS uses as its internal format a variant of WKB known as EWKB. This variant provides support for Z and M coordinates as well as embedded SRID values. PostGIS also defines an corresponding EWKT format adding Z and M support and SRIDs to WKT, and provides conversion functions. The EWKB and EWKT variants are commonly used and so are supported by \RGeo's WKB and WKT parsers.
|
398
402
|
|
399
403
|
=== 5.5. \RGeo ActiveRecord Integration
|
400
404
|
|
401
|
-
\RGeo provides extra support for web applications built on Ruby On Rails or similar frameworks that use the ActiveRecord library, in the form of a suite of ActiveRecord connection adapters for the various spatial databases we have covered. These connection adapters subclass the stock database connection adapters, and add support for the \RGeo geometric data types. You can create spatial columns and indexes using extensions to the ActiveRecord schema definition functions, and the appropriate fields on your ActiveRecord objects will appear as \RGeo spatial data objects. Using one of these connection adapters is probably the easiest way to integrate your Rails application with a spatial database.
|
405
|
+
\RGeo provides extra support for web applications built on Ruby On Rails or similar frameworks that use the ActiveRecord library, in the form of a suite of ActiveRecord connection adapters for the various spatial databases we have covered. These connection adapters subclass the stock database connection adapters, and add support for the \RGeo geometric data types. You can create spatial columns and indexes using extensions to the ActiveRecord schema definition functions, and the appropriate fields on your ActiveRecord objects will appear as \RGeo spatial data objects. Some of these adapters also modify ActiveRecord's rake tasks to help automate the process of creating and maintaining spatial databases. Using one of these connection adapters is probably the easiest way to integrate your Rails application with a spatial database.
|
402
406
|
|
403
407
|
\RGeo's spatial ActiveRecord adapters are provided in separate gems, named according to the recommended convention. These are the names of these connection adapters:
|
404
408
|
|
405
409
|
* *mysqlspatial*: Subclasses the mysql adapter and adds support for MySQL's spatial types. Available as the <b>activerecord-mysqlspatial-adapter</b> gem.
|
406
|
-
*
|
410
|
+
* <b>mysql2spatial</b>: Subclasses the mysql2 adapter and adds support for MySQL's spatial types. Available as the <b>activerecord-mysql2spatial-adapter</b> gem.
|
407
411
|
* *spatialite*: Subclasses the sqlite3 adapter and adds support for the SpatiaLite extension. Available as the <b>activerecord-spatialite-adapter</b> gem.
|
408
412
|
* *postgis*: Subclasses the postgresql adapter and adds support for the PostGIS extension. Available as the <b>activerecord-postgis-adapter</b> gem.
|
409
413
|
|
@@ -415,11 +419,11 @@ When writing a location-aware application, you will often need to interact with
|
|
415
419
|
|
416
420
|
{ESRI}[http://www.esri.com/] is one of the oldest and most well-known GIS corporations, developing a suite of applications including the venerable {ArcGIS}[http://www.esri.com/software/arcgis/index.html]. ESRI also created the Shapefile, a geospatial data file format that has become a <i>de facto</i> standard despite its legacy and somewhat awkward characteristics. Today, many of the widely-available geospatial data sets are distributed as shapefiles.
|
417
421
|
|
418
|
-
The shapefile format is specified in an ESRI {whitepaper}[http://www.esri.com/library/whitepapers/pdfs/shapefile.pdf]. It typically comprises three files:
|
422
|
+
The shapefile format is specified in an ESRI {whitepaper}[http://www.esri.com/library/whitepapers/pdfs/shapefile.pdf]. It typically comprises three files: the main file "*.shp" containing the actual geometric data, a corresponding index file "*.shx" providing offsets into the .shp file to support random access, and a corresponding file "*.dbf" in dBASE format that stores arbitrary attributes for the shape records. Many GIS systems can read and/or write shapefiles. SpatiaLite can treat a shapefile as an external "virtual table". An optional \RGeo module, RGeo::Shapefile (distributed as the gem <b>rgeo-shapefile</b>) can read shapefiles and expose their contents as \RGeo's geometric data types.
|
419
423
|
|
420
424
|
=== 6.2. GeoJSON and Location-Based Services
|
421
425
|
|
422
|
-
Location is becoming a common feature of web services as well. An emerging standard in the encoding of geographic data in a web service is {GeoJSON}[http://www.geojson.org/], an geospatial data format based on JSON. GeoJSON can encode any of the OGR geometry types, along with attributes, bounding boxes, and coordinate system specifications. {SimpleGeo}[http://www.simplegeo.com/] is one of several high-profile location based APIs now using GeoJSON. \RGeo also provides an optional module RGeo::GeoJSON (
|
426
|
+
Location is becoming a common feature of web services as well. An emerging standard in the encoding of geographic data in a web service is {GeoJSON}[http://www.geojson.org/], an geospatial data format based on JSON. GeoJSON can encode any of the OGR geometry types, along with attributes, bounding boxes, and coordinate system specifications. {SimpleGeo}[http://www.simplegeo.com/] is one of several high-profile location based APIs now using GeoJSON. \RGeo also provides an optional module RGeo::GeoJSON (distributed as the gem <b>rgeo-geojson</b>) that can read and write this format.
|
423
427
|
|
424
428
|
Other common formats that may be used by web services include {GeoRSS}[http://www.georss.org/], an extension to RSS and Atom for geotagging RSS feed entries, and {KML}[http://www.opengeospatial.org/standards/kml], an XML-based markup language for geographic information originally developed by Google and recently adopted as an OGC standard. The GeoRuby library provides rudimentary support for these formats. \RGeo does not yet, but appropriate optional modules are on the to-do list.
|
425
429
|
|
@@ -431,5 +435,6 @@ At the time of this writing, a number of open source geospatial tools and librar
|
|
431
435
|
|
432
436
|
== History
|
433
437
|
|
434
|
-
* Version 0.1 / 5 Dec 2010: Initial draft
|
435
|
-
* Version 0.2 / 7 Dec 2010: More code examples and other minor updates
|
438
|
+
* Version 0.1 / 5 Dec 2010: Initial draft
|
439
|
+
* Version 0.2 / 7 Dec 2010: More code examples and other minor updates
|
440
|
+
* Version 0.3 / 17 Feb 2011: Further minor clarifications and fixes, and coverage of features in newer \RGeo releases
|
data/Version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.5
|
@@ -64,10 +64,10 @@ module RGeo
|
|
64
64
|
#
|
65
65
|
# Options include:
|
66
66
|
#
|
67
|
-
# <tt>:ignore_z</tt
|
67
|
+
# [<tt>:ignore_z</tt>]
|
68
68
|
# If true, ignore z coordinates even if the factory supports them.
|
69
69
|
# Default is false.
|
70
|
-
# <tt>:ignore_m</tt
|
70
|
+
# [<tt>:ignore_m</tt>]
|
71
71
|
# If true, ignore m coordinates even if the factory supports them.
|
72
72
|
# Default is false.
|
73
73
|
|
@@ -78,6 +78,10 @@ module RGeo
|
|
78
78
|
end
|
79
79
|
|
80
80
|
|
81
|
+
# Returns a negative value if the point is to the left,
|
82
|
+
# a positive value if the point is to the right, or
|
83
|
+
# 0 if the point is collinear to the segment.
|
84
|
+
|
81
85
|
def side(p_)
|
82
86
|
px_ = p_.x
|
83
87
|
py_ = p_.y
|
@@ -89,9 +93,7 @@ module RGeo
|
|
89
93
|
if @lensq == 0
|
90
94
|
nil
|
91
95
|
else
|
92
|
-
|
93
|
-
py_ = @sy - p_.y
|
94
|
-
- (@dx * px_ + @dy * py_) / @lensq
|
96
|
+
(@dx * (p_.x - @sx) + @dy * (p_.y - @sy)) / @lensq
|
95
97
|
end
|
96
98
|
end
|
97
99
|
|
@@ -108,16 +110,41 @@ module RGeo
|
|
108
110
|
|
109
111
|
def intersects_segment?(seg_)
|
110
112
|
s2_ = seg_.s
|
113
|
+
# Handle degenerate cases
|
114
|
+
if seg_.degenerate?
|
115
|
+
if @lensq == 0
|
116
|
+
return @s == s2_
|
117
|
+
else
|
118
|
+
return contains_point?(s2_)
|
119
|
+
end
|
120
|
+
elsif @lensq == 0
|
121
|
+
return seg_.contains_point?(@s)
|
122
|
+
end
|
123
|
+
# Both segments have nonzero length.
|
111
124
|
sx2_ = s2_.x
|
112
125
|
sy2_ = s2_.y
|
113
126
|
dx2_ = seg_.dx
|
114
127
|
dy2_ = seg_.dy
|
115
128
|
denom_ = @dx*dy2_ - @dy*dx2_
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
129
|
+
if denom_ == 0
|
130
|
+
# Segments are parallel. Make sure they are collinear.
|
131
|
+
return false unless side(s2_) == 0
|
132
|
+
# 1-D check.
|
133
|
+
ts_ = (@dx * (sx2_ - @sx) + @dy * (sy2_ - @sy)) / @lensq
|
134
|
+
te_ = (@dx * (sx2_ + dx2_ - @sx) + @dy * (sy2_ + dy2_ - @sy)) / @lensq
|
135
|
+
if ts_ < te_
|
136
|
+
te_ >= 0.0 && ts_ <= 1.0
|
137
|
+
else
|
138
|
+
ts_ >= 0.0 && te_ <= 1.0
|
139
|
+
end
|
140
|
+
else
|
141
|
+
# Segments are not parallel. Check the intersection of their
|
142
|
+
# containing lines.
|
143
|
+
t_ = (dy2_ * (sx2_ - @sx) + dx2_ * (@sy - sy2_)) / denom_
|
144
|
+
return false if t_ < 0.0 || t_ > 1.0
|
145
|
+
t2_ = (@dy * (sx2_ - @sx) + @dx * (@sy - sy2_)) / denom_
|
146
|
+
t2_ >= 0.0 && t2_ <= 1.0
|
147
|
+
end
|
121
148
|
end
|
122
149
|
|
123
150
|
|
@@ -90,25 +90,25 @@ module RGeo
|
|
90
90
|
#
|
91
91
|
# Options include:
|
92
92
|
#
|
93
|
-
# <tt>:srid</tt
|
93
|
+
# [<tt>:srid</tt>]
|
94
94
|
# Set the SRID returned by geometries created by this factory.
|
95
95
|
# Default is 0.
|
96
|
-
# <tt>:proj4</tt
|
96
|
+
# [<tt>:proj4</tt>]
|
97
97
|
# The coordinate system in Proj4 format, either as a
|
98
98
|
# CoordSys::Proj4 object or as a string or hash representing the
|
99
99
|
# proj4 format. Optional.
|
100
|
-
# <tt>:coord_sys</tt
|
100
|
+
# [<tt>:coord_sys</tt>]
|
101
101
|
# The coordinate system in OGC form, either as a subclass of
|
102
102
|
# CoordSys::CS::CoordinateSystem, or as a string in WKT format.
|
103
103
|
# Optional.
|
104
|
-
# <tt>:srs_database</tt
|
104
|
+
# [<tt>:srs_database</tt>]
|
105
105
|
# Optional. If provided, the value should be an implementation of
|
106
106
|
# CoordSys::SRSDatabase::Interface. If both this and an SRID are
|
107
107
|
# provided, they are used to look up the proj4 and coord_sys
|
108
108
|
# objects from a spatial reference system database.
|
109
|
-
# <tt>:has_z_coordinate</tt
|
109
|
+
# [<tt>:has_z_coordinate</tt>]
|
110
110
|
# Support a Z coordinate. Default is false.
|
111
|
-
# <tt>:has_m_coordinate</tt
|
111
|
+
# [<tt>:has_m_coordinate</tt>]
|
112
112
|
# Support an M coordinate. Default is false.
|
113
113
|
|
114
114
|
def simple_factory(opts_={})
|
data/lib/rgeo/coord_sys/proj4.rb
CHANGED
@@ -172,7 +172,7 @@ module RGeo
|
|
172
172
|
#
|
173
173
|
# Recognized options include:
|
174
174
|
#
|
175
|
-
# <tt>:radians</tt
|
175
|
+
# [<tt>:radians</tt>]
|
176
176
|
# If set to true, then this proj4 will represent geographic
|
177
177
|
# (latitude/longitude) coordinates in radians rather than
|
178
178
|
# degrees. If this is a geographic coordinate system, then its
|
@@ -55,57 +55,57 @@ module RGeo
|
|
55
55
|
#
|
56
56
|
# Options include:
|
57
57
|
#
|
58
|
-
# <tt>:ar_class</tt
|
58
|
+
# [<tt>:ar_class</tt>]
|
59
59
|
# An ActiveRecord class to use. You may provide this if you
|
60
60
|
# already have an ActiveRecord class that accesses the table.
|
61
61
|
# If not provided, an ActiveRecord class will be generated
|
62
62
|
# for you, using the <tt>:ar_base_class</tt>,
|
63
63
|
# <tt>:database_config</tt>, and <tt>:table_name</tt> options.
|
64
|
-
# <tt>:ar_base_class</tt
|
64
|
+
# [<tt>:ar_base_class</tt>]
|
65
65
|
# Specify an ActiveRecord base class to use when generating an
|
66
66
|
# ActiveRecord class. Default is ::ActiveRecord::Base. You may
|
67
67
|
# want to use this if you have a base class already that
|
68
68
|
# specifies an existing database connection and/or other
|
69
69
|
# class-scope options.
|
70
|
-
# <tt>:database_config</tt
|
70
|
+
# [<tt>:database_config</tt>]
|
71
71
|
# If provided, <tt>establish_connection</tt> will be called on
|
72
72
|
# the generated ActiveRecord class, with the given value.
|
73
|
-
# <tt>:table_name</tt
|
73
|
+
# [<tt>:table_name</tt>]
|
74
74
|
# The table name for the new ActiveRecord class. Defaults to
|
75
75
|
# the value <tt>spatial_ref_sys</tt>, which is the OGC-specified
|
76
76
|
# name for this table.
|
77
|
-
# <tt>:srid_column</tt
|
77
|
+
# [<tt>:srid_column</tt>]
|
78
78
|
# The name of the SRID column. Defaults to "srid", which is the
|
79
79
|
# OGC-specified name for this column.
|
80
|
-
# <tt>:auth_name_column</tt
|
80
|
+
# [<tt>:auth_name_column</tt>]
|
81
81
|
# The name of the authority name column. On an OGC-compliant
|
82
82
|
# database, this column should be named "auth_name". However,
|
83
83
|
# the default is set to nil; you should set this option
|
84
84
|
# explicitly if you want to read the authority name.
|
85
|
-
# <tt>:auth_srid_column</tt
|
85
|
+
# [<tt>:auth_srid_column</tt>]
|
86
86
|
# The name of the authority srid column. On an OGC-compliant
|
87
87
|
# database, this column should be named "auth_srid". However,
|
88
88
|
# the default is set to nil; you should set this option
|
89
89
|
# explicitly if you want to read the authority's srid.
|
90
|
-
# <tt>:name_column</tt
|
90
|
+
# [<tt>:name_column</tt>]
|
91
91
|
# The name of the coordinate system name column. This column is
|
92
92
|
# not part of the OGC spec, but it is included in some spatial
|
93
93
|
# database implementations. Default is nil.
|
94
|
-
# <tt>:description_column</tt
|
94
|
+
# [<tt>:description_column</tt>]
|
95
95
|
# The name of the coordinate system description column. This
|
96
96
|
# column is not part of the OGC spec, but may be included in
|
97
97
|
# some spatial database implementations. Default is nil.
|
98
|
-
# <tt>:srtext_column</tt
|
98
|
+
# [<tt>:srtext_column</tt>]
|
99
99
|
# The name of the spatial reference WKT column. On an
|
100
100
|
# OGC-compliant database, this column should be named "srtext".
|
101
101
|
# However, not all databases include this column, so the default
|
102
102
|
# is set to nil; you should set this option explicitly if you
|
103
103
|
# want to read the OGC coordinate system specification.
|
104
|
-
# <tt>:proj4text_column</tt
|
104
|
+
# [<tt>:proj4text_column</tt>]
|
105
105
|
# The name of the Proj4 format projection spec column. This
|
106
106
|
# column is not part of the OGC spec, but may be included in
|
107
107
|
# some spatial database implementations. Default is nil.
|
108
|
-
# <tt>:cache</tt
|
108
|
+
# [<tt>:cache</tt>]
|
109
109
|
# If set to true, entries are cached when first retrieved, so
|
110
110
|
# subsequent requests do not have to make a database round trip.
|
111
111
|
# Default is false.
|
@@ -92,18 +92,18 @@ module RGeo
|
|
92
92
|
#
|
93
93
|
# Some attribute inputs have special behaviors:
|
94
94
|
#
|
95
|
-
# <tt>:coord_sys</tt
|
95
|
+
# [<tt>:coord_sys</tt>]
|
96
96
|
# You can pass a CS coordinate system object, or a string in
|
97
97
|
# WKT format.
|
98
|
-
# <tt>:proj4</tt
|
98
|
+
# [<tt>:proj4</tt>]
|
99
99
|
# You can pass a Proj4 object, or a proj4-format string.
|
100
|
-
# <tt>:name</tt
|
100
|
+
# [<tt>:name</tt>]
|
101
101
|
# If the name is not provided directly, it is taken from the
|
102
102
|
# coord_sys.
|
103
|
-
# <tt>:authority</tt
|
103
|
+
# [<tt>:authority</tt>]
|
104
104
|
# If the authority name is not provided directly, it is taken
|
105
105
|
# from the coord_sys.
|
106
|
-
# <tt>:authority_code</tt
|
106
|
+
# [<tt>:authority_code</tt>]
|
107
107
|
# If the authority code is not provided directly, it is taken
|
108
108
|
# from the coord_sys.
|
109
109
|
|
@@ -55,7 +55,7 @@ module RGeo
|
|
55
55
|
#
|
56
56
|
# These options are recognized:
|
57
57
|
#
|
58
|
-
# <tt>:dir</tt
|
58
|
+
# [<tt>:dir</tt>]
|
59
59
|
# The path for the share/proj directory that contains the
|
60
60
|
# requested data file. By default, the Proj4Data class will
|
61
61
|
# try a number of directories for you, including
|
@@ -65,7 +65,7 @@ module RGeo
|
|
65
65
|
# option. You may also pass nil as the value, in which case all
|
66
66
|
# the normal lookup paths will be disabled, and you will have to
|
67
67
|
# provide the full path as the file name.
|
68
|
-
# <tt>:cache</tt
|
68
|
+
# [<tt>:cache</tt>]
|
69
69
|
# If set to true, this class caches previously looked up entries
|
70
70
|
# so subsequent lookups do not have to reread the file. If set
|
71
71
|
# to <tt>:read_all</tt>, then ALL values in the file are read in
|
@@ -73,7 +73,7 @@ module RGeo
|
|
73
73
|
# <tt>:preload</tt>, then ALL values in the file are read in
|
74
74
|
# immediately when the database is created. Default is false,
|
75
75
|
# indicating that the file will be reread on every lookup.
|
76
|
-
# <tt>:authority</tt
|
76
|
+
# [<tt>:authority</tt>]
|
77
77
|
# If set, its value is taken as the authority name for all
|
78
78
|
# entries. The authority code will be set to the identifier. If
|
79
79
|
# not set, then the authority fields of entries will be blank.
|
@@ -56,7 +56,7 @@ module RGeo
|
|
56
56
|
#
|
57
57
|
# Options:
|
58
58
|
#
|
59
|
-
# <tt>:cache</tt
|
59
|
+
# [<tt>:cache</tt>]
|
60
60
|
# If set to true, lookup results are cached so if the same URL
|
61
61
|
# is requested again, the result is served from cache rather
|
62
62
|
# than issuing another HTTP request. Default is false.
|
@@ -54,7 +54,7 @@ module RGeo
|
|
54
54
|
#
|
55
55
|
# Options:
|
56
56
|
#
|
57
|
-
# <tt>:cache</tt
|
57
|
+
# [<tt>:cache</tt>]
|
58
58
|
# If set to true, lookup results are cached so if the same URL
|
59
59
|
# is requested again, the result is served from cache rather
|
60
60
|
# than issuing another HTTP request. Default is false.
|
data/lib/rgeo/feature/factory.rb
CHANGED
@@ -91,17 +91,17 @@ module RGeo
|
|
91
91
|
#
|
92
92
|
# Currently defined well-known properties are:
|
93
93
|
#
|
94
|
-
# <tt>:has_z_coordinate</tt
|
94
|
+
# [<tt>:has_z_coordinate</tt>]
|
95
95
|
# Set to true if geometries created by this factory include a Z
|
96
96
|
# coordinate, and the Point#z method is available.
|
97
|
-
# <tt>:has_m_coordinate</tt
|
97
|
+
# [<tt>:has_m_coordinate</tt>]
|
98
98
|
# Set to true if geometries created by this factory include a M
|
99
99
|
# coordinate, and the Point#z method is available.
|
100
|
-
# <tt>:is_cartesian</tt
|
100
|
+
# [<tt>:is_cartesian</tt>]
|
101
101
|
# Set to true if this Factory guarantees that it operates in
|
102
102
|
# Cartesian geometry. If false or nil, no such guarantee is made,
|
103
103
|
# though it is possible the geometries may still be Cartesian.
|
104
|
-
# <tt>:is_geographic</tt
|
104
|
+
# [<tt>:is_geographic</tt>]
|
105
105
|
# Set to true if this Factory's coordinate system is meant to be
|
106
106
|
# interpreted as x=longitude and y=latitude. If false or nil, no
|
107
107
|
# information is present about whether the coordinate system is
|
@@ -301,13 +301,13 @@ module RGeo
|
|
301
301
|
# (which again may or may not already be the type of the original
|
302
302
|
# object), and a hash of additional flags. These flags are:
|
303
303
|
#
|
304
|
-
# <tt>:keep_subtype</tt
|
304
|
+
# [<tt>:keep_subtype</tt>]
|
305
305
|
# indicates whether to keep the subtype if casting to a supertype
|
306
306
|
# of the current type
|
307
|
-
# <tt>:force_new</tt
|
307
|
+
# [<tt>:force_new</tt>]
|
308
308
|
# indicates whether to force the creation of a new object even if
|
309
309
|
# the original is already of the desired factory and type
|
310
|
-
# <tt>:project</tt
|
310
|
+
# [<tt>:project</tt>]
|
311
311
|
# indicates whether to project the coordinates from the source to
|
312
312
|
# the destination proj4 coordinate system, if available
|
313
313
|
#
|
@@ -80,31 +80,31 @@ module RGeo
|
|
80
80
|
# recommendation only. There is no hard requirement for any
|
81
81
|
# particular factory generator to support them.
|
82
82
|
#
|
83
|
-
# <tt>:strict</tt
|
83
|
+
# [<tt>:strict</tt>]
|
84
84
|
# If true, return nil or raise an exception if any configuration
|
85
85
|
# was not recognized or not supportable. Otherwise, if false,
|
86
86
|
# the generator should attempt to do its best to return some
|
87
87
|
# viable factory, even if it does not strictly match the
|
88
88
|
# requested configuration. Default is usually false.
|
89
|
-
# <tt>:srid</tt
|
89
|
+
# [<tt>:srid</tt>]
|
90
90
|
# The SRID for the factory and objects it creates.
|
91
91
|
# Default is usually 0.
|
92
|
-
# <tt>:proj4</tt
|
92
|
+
# [<tt>:proj4</tt>]
|
93
93
|
# The coordinate system in Proj4 format, either as a
|
94
94
|
# CoordSys::Proj4 object or as a string or hash representing the
|
95
95
|
# proj4 format. This is usually an optional parameter; the default
|
96
96
|
# is usually nil.
|
97
|
-
# <tt>:coord_sys</tt
|
97
|
+
# [<tt>:coord_sys</tt>]
|
98
98
|
# The coordinate system in OGC form, either as a subclass of
|
99
99
|
# CoordSys::CS::CoordinateSystem, or as a string in WKT format.
|
100
100
|
# This is usually an optional parameter; the default is usually
|
101
101
|
# nil.
|
102
|
-
# <tt>:srs_database</tt
|
102
|
+
# [<tt>:srs_database</tt>]
|
103
103
|
# If provided, look up the Proj4 and OGC coordinate systems from
|
104
104
|
# the given database and SRID.
|
105
|
-
# <tt>:has_z_coordinate</tt
|
105
|
+
# [<tt>:has_z_coordinate</tt>]
|
106
106
|
# Support Z coordinates. Default is usually false.
|
107
|
-
# <tt>:has_m_coordinate</tt
|
107
|
+
# [<tt>:has_m_coordinate</tt>]
|
108
108
|
# Support M coordinates. Default is usually false.
|
109
109
|
|
110
110
|
def call(config_={})
|
@@ -68,27 +68,26 @@ module RGeo
|
|
68
68
|
#
|
69
69
|
# The Geometry model defines three forms of equivalence.
|
70
70
|
#
|
71
|
-
# Spatial equivalence
|
72
|
-
#
|
73
|
-
#
|
74
|
-
# be different representations of that region. For example, a
|
71
|
+
# * <b>Spatial equivalence</b> is the weakest form of equivalence,
|
72
|
+
# indicating that the objects represent the same region of space,
|
73
|
+
# but may be different representations of that region. For example,
|
75
74
|
# POINT(0 0) and a MULTIPOINT(0 0) are spatially equivalent, as are
|
76
75
|
# LINESTRING(0 0, 10 10) and
|
77
76
|
# GEOMETRYCOLLECTION(POINT(0 0), LINESTRING(0 0, 10 10, 0 0)).
|
78
77
|
# As a general rule, objects must have factories that are
|
79
78
|
# Factory#eql? in order to be spatially equivalent.
|
80
|
-
#
|
81
|
-
#
|
82
|
-
# that the
|
83
|
-
# different objects. All objectively equivalent objects are
|
84
|
-
# equivalent, but not all spatially equivalent objects are
|
79
|
+
#
|
80
|
+
# * <b>Objective equivalence</b> is a stronger form of equivalence,
|
81
|
+
# indicating that the objects are the same representation, but may
|
82
|
+
# be different objects. All objectively equivalent objects are
|
83
|
+
# spatially equivalent, but not all spatially equivalent objects are
|
85
84
|
# objectively equivalent. For example, none of the examples in the
|
86
85
|
# spatial equivalence section above are objectively equivalent.
|
87
86
|
# However, two separate objects that both represent POINT(1 2) are
|
88
87
|
# objectively equivalent as well as spatially equivalent.
|
89
|
-
#
|
90
|
-
#
|
91
|
-
# references refer to the same object. Of course, all pairs of
|
88
|
+
#
|
89
|
+
# * <b>Objective identity</b> is the strongest form, indicating that
|
90
|
+
# the references refer to the same object. Of course, all pairs of
|
92
91
|
# references with the same objective identity are both objectively
|
93
92
|
# equivalent and spatially equivalent.
|
94
93
|
#
|
data/lib/rgeo/feature/types.rb
CHANGED
@@ -110,20 +110,20 @@ module RGeo
|
|
110
110
|
# Parameters may be provided as a hash, or as separate arguments.
|
111
111
|
# Hash keys are as follows:
|
112
112
|
#
|
113
|
-
# <tt>:factory</tt
|
113
|
+
# [<tt>:factory</tt>]
|
114
114
|
# Set the factory to the given factory. If this argument is not
|
115
115
|
# given, the original object's factory is kept.
|
116
|
-
# <tt>:type</tt
|
116
|
+
# [<tt>:type</tt>]
|
117
117
|
# Cast to the given type, which must be a module in the
|
118
118
|
# RGeo::Feature namespace. If this argument is not given, the
|
119
119
|
# result keeps the same type as the original.
|
120
|
-
# <tt>:project</tt
|
120
|
+
# [<tt>:project</tt>]
|
121
121
|
# If this is set to true, and both the original and new factories
|
122
122
|
# support proj4 projections, then the cast will also cause the
|
123
123
|
# coordinates to be transformed between those two projections.
|
124
124
|
# If set to false, the coordinates are not modified. Default is
|
125
125
|
# false.
|
126
|
-
# <tt>:keep_subtype</tt
|
126
|
+
# [<tt>:keep_subtype</tt>]
|
127
127
|
# Value must be a boolean indicating whether to keep the subtype
|
128
128
|
# of the original. If set to false, casting to a particular type
|
129
129
|
# always casts strictly to that type, even if the old type is a
|
@@ -133,7 +133,7 @@ module RGeo
|
|
133
133
|
# LinearRing is already a more specific subtype. If you set this
|
134
134
|
# value to true, the casted object will remain a LinearRing.
|
135
135
|
# Default is false.
|
136
|
-
# <tt>:force_new</tt
|
136
|
+
# [<tt>:force_new</tt>]
|
137
137
|
# Always return a newly-created object, even if neither the type
|
138
138
|
# nor factory is modified. Normally, if this is set to false, and
|
139
139
|
# a cast is not set to modify either the factory or type, the
|
@@ -82,11 +82,11 @@ module RGeo
|
|
82
82
|
# You may use the following options when creating a spherical
|
83
83
|
# factory:
|
84
84
|
#
|
85
|
-
# <tt>:has_z_coordinate</tt
|
85
|
+
# [<tt>:has_z_coordinate</tt>]
|
86
86
|
# Support a Z coordinate. Default is false.
|
87
|
-
# <tt>:has_m_coordinate</tt
|
87
|
+
# [<tt>:has_m_coordinate</tt>]
|
88
88
|
# Support an M coordinate. Default is false.
|
89
|
-
# <tt>:proj4</tt
|
89
|
+
# [<tt>:proj4</tt>]
|
90
90
|
# Provide the coordinate system in Proj4 format. You may pass
|
91
91
|
# either an RGeo::CoordSys::Proj4 object, or a string or hash
|
92
92
|
# containing the Proj4 parameters. This coordinate system must be
|
@@ -94,18 +94,18 @@ module RGeo
|
|
94
94
|
# "popular visualization CRS" (EPSG 4055), represented by
|
95
95
|
# "<tt>+proj=longlat +a=6378137 +b=6378137 +towgs84=0,0,0,0,0,0,0 +no_defs</tt>".
|
96
96
|
# Has no effect if Proj4 is not available.
|
97
|
-
# <tt>:coord_sys</tt
|
97
|
+
# [<tt>:coord_sys</tt>]
|
98
98
|
# Provide a coordinate system in OGC format, either as an object
|
99
99
|
# (one of the CoordSys::CS classes) or as a string in WKT format.
|
100
100
|
# This coordinate system must be a GeographicCoordinateSystem.
|
101
101
|
# The default is the "popular visualization CRS" (EPSG 4055).
|
102
|
-
# <tt>:srid</tt
|
102
|
+
# [<tt>:srid</tt>]
|
103
103
|
# The SRID that should be returned by features from this factory.
|
104
104
|
# Default is 4055, indicating EPSG 4055, the "popular
|
105
105
|
# visualization crs". You may alternatively wish to set the srid
|
106
106
|
# to 4326, indicating the WGS84 crs, but note that that value
|
107
107
|
# implies an ellipsoidal datum, not a spherical datum.
|
108
|
-
# <tt>:srs_database</tt
|
108
|
+
# [<tt>:srs_database</tt>]
|
109
109
|
# Optional. If provided, the value should be an implementation of
|
110
110
|
# CoordSys::SRSDatabase::Interface. If both this and an SRID are
|
111
111
|
# provided, they are used to look up the proj4 and coord_sys
|
@@ -168,9 +168,9 @@ module RGeo
|
|
168
168
|
# You may use the following options when creating a simple_mercator
|
169
169
|
# factory:
|
170
170
|
#
|
171
|
-
# <tt>:has_z_coordinate</tt
|
171
|
+
# [<tt>:has_z_coordinate</tt>]
|
172
172
|
# Support a Z coordinate. Default is false.
|
173
|
-
# <tt>:has_m_coordinate</tt
|
173
|
+
# [<tt>:has_m_coordinate</tt>]
|
174
174
|
# Support an M coordinate. Default is false.
|
175
175
|
#
|
176
176
|
# You may also provide options understood by the underlying
|
@@ -220,24 +220,24 @@ module RGeo
|
|
220
220
|
# Following are detailed descriptions of the various options you can
|
221
221
|
# pass to this method.
|
222
222
|
#
|
223
|
-
# <tt>:projection_factory</tt
|
223
|
+
# [<tt>:projection_factory</tt>]
|
224
224
|
# Specify an existing Cartesian factory to use for the projection.
|
225
225
|
# This factory must have a non-nil Proj4. If this is provided, any
|
226
226
|
# <tt>:projection_proj4</tt>, <tt>:projection_coord_sys</tt>, and
|
227
227
|
# <tt>:projection_srid</tt> are ignored.
|
228
|
-
# <tt>:projection_proj4</tt
|
228
|
+
# [<tt>:projection_proj4</tt>]
|
229
229
|
# Specify a Proj4 projection to use to construct the projection
|
230
230
|
# factory. This may be specified as a CoordSys::Proj4 object, or
|
231
231
|
# as a Proj4 string or hash representation.
|
232
|
-
# <tt>:projection_coord_sys</tt
|
232
|
+
# [<tt>:projection_coord_sys</tt>]
|
233
233
|
# Specify a OGC coordinate system for the projection. This may be
|
234
234
|
# specified as an RGeo::CoordSys::CS::GeographicCoordinateSystem
|
235
235
|
# object, or as a String in OGC WKT format. Optional.
|
236
|
-
# <tt>:projection_srid</tt
|
236
|
+
# [<tt>:projection_srid</tt>]
|
237
237
|
# The SRID value to use for the projection factory. Defaults to
|
238
238
|
# the given projection coordinate system's authority code, or to
|
239
239
|
# 0 if no projection coordinate system is known.
|
240
|
-
# <tt>:proj4</tt
|
240
|
+
# [<tt>:proj4</tt>]
|
241
241
|
# A proj4 projection for the geographic (lat-lon) factory. You may
|
242
242
|
# pass either an RGeo::CoordSys::Proj4 object, or a string or hash
|
243
243
|
# containing the Proj4 parameters. This coordinate system must be
|
@@ -246,7 +246,7 @@ module RGeo
|
|
246
246
|
# Generally, you should leave it at the default unless you want
|
247
247
|
# the geographic coordinate system to be based on a different
|
248
248
|
# horizontal datum than the projection.
|
249
|
-
# <tt>:coord_sys</tt
|
249
|
+
# [<tt>:coord_sys</tt>]
|
250
250
|
# An OGC coordinate system for the geographic (lat-lon) factory,
|
251
251
|
# which may be an RGeo::CoordSys::CS::GeographicCoordinateSystem
|
252
252
|
# object or a string in OGC WKT format. It defaults to the
|
@@ -254,21 +254,21 @@ module RGeo
|
|
254
254
|
# Generally, you should leave it at the default unless you want
|
255
255
|
# the geographic coordinate system to be based on a different
|
256
256
|
# horizontal datum than the projection.
|
257
|
-
# <tt>:srid</tt
|
257
|
+
# [<tt>:srid</tt>]
|
258
258
|
# The SRID value to use for the main geographic factory. Defaults
|
259
259
|
# to the given geographic coordinate system's authority code, or
|
260
260
|
# to 0 if no geographic coordinate system is known.
|
261
|
-
# <tt>:srs_database</tt
|
261
|
+
# [<tt>:srs_database</tt>]
|
262
262
|
# Optional. If provided, the value should be an implementation of
|
263
263
|
# CoordSys::SRSDatabase::Interface. If both this and an SRID are
|
264
264
|
# provided, they are used to look up the proj4 and coord_sys
|
265
265
|
# objects from a spatial reference system database.
|
266
|
-
# <tt>:has_z_coordinate</tt
|
266
|
+
# [<tt>:has_z_coordinate</tt>]
|
267
267
|
# Support a Z coordinate. Default is false.
|
268
268
|
# Note: this is ignored if a <tt>:projection_factory</tt> is
|
269
269
|
# provided; in that case, the geographic factory's z-coordinate
|
270
270
|
# availability will match the projection factory's setting.
|
271
|
-
# <tt>:has_m_coordinate</tt
|
271
|
+
# [<tt>:has_m_coordinate</tt>]
|
272
272
|
# Support an M coordinate. Default is false.
|
273
273
|
# Note: this is ignored if a <tt>:projection_factory</tt> is
|
274
274
|
# provided; in that case, the geographic factory's m-coordinate
|
@@ -46,7 +46,13 @@ module RGeo
|
|
46
46
|
|
47
47
|
def initialize(geography_factory_, opts_={})
|
48
48
|
@geography_factory = geography_factory_
|
49
|
-
@projection_factory = Cartesian.preferred_factory(:srid => 3785,
|
49
|
+
@projection_factory = Cartesian.preferred_factory(:srid => 3785,
|
50
|
+
:proj4 => SimpleMercatorProjector._proj4_3785,
|
51
|
+
:coord_sys => SimpleMercatorProjector._coordsys_3785,
|
52
|
+
:buffer_resolution => opts_[:buffer_resolution],
|
53
|
+
:lenient_multi_polygon_assertions => opts_[:lenient_multi_polygon_assertions],
|
54
|
+
:has_z_coordinate => opts_[:has_z_coordinate],
|
55
|
+
:has_m_coordinate => opts_[:has_m_coordinate])
|
50
56
|
end
|
51
57
|
|
52
58
|
|
@@ -100,7 +106,7 @@ module RGeo
|
|
100
106
|
@geography_factory.line_string(geometry_.points.map{ |p_| unproject(p_) })
|
101
107
|
when Feature::Polygon
|
102
108
|
@geography_factory.polygon(unproject(geometry_.exterior_ring),
|
103
|
-
|
109
|
+
geometry_.interior_rings.map{ |p_| unproject(p_) })
|
104
110
|
when Feature::MultiPoint
|
105
111
|
@geography_factory.multi_point(geometry_.map{ |p_| unproject(p_) })
|
106
112
|
when Feature::MultiLineString
|
@@ -121,7 +127,9 @@ module RGeo
|
|
121
127
|
|
122
128
|
|
123
129
|
def limits_window
|
124
|
-
@limits_window ||= ProjectedWindow.new(@geography_factory,
|
130
|
+
@limits_window ||= ProjectedWindow.new(@geography_factory,
|
131
|
+
-20037508.342789, -20037508.342789, 20037508.342789, 20037508.342789,
|
132
|
+
:is_limits => true)
|
125
133
|
end
|
126
134
|
|
127
135
|
|
data/lib/rgeo/geos/interface.rb
CHANGED
@@ -71,13 +71,13 @@ module RGeo
|
|
71
71
|
#
|
72
72
|
# Options include:
|
73
73
|
#
|
74
|
-
# <tt>:lenient_multi_polygon_assertions</tt
|
74
|
+
# [<tt>:lenient_multi_polygon_assertions</tt>]
|
75
75
|
# If set to true, assertion checking on MultiPolygon is disabled.
|
76
76
|
# This may speed up creation of MultiPolygon objects, at the
|
77
77
|
# expense of not doing the proper checking for OGC MultiPolygon
|
78
78
|
# compliance. See RGeo::Feature::MultiPolygon for details on
|
79
79
|
# the MultiPolygon assertions. Default is false.
|
80
|
-
# <tt>:buffer_resolution</tt
|
80
|
+
# [<tt>:buffer_resolution</tt>]
|
81
81
|
# The resolution of buffers around geometries created by this
|
82
82
|
# factory. This controls the number of line segments used to
|
83
83
|
# approximate curves. The default is 1, which causes, for
|
@@ -85,25 +85,25 @@ module RGeo
|
|
85
85
|
# 4-sided polygon. A resolution of 2 would cause that buffer
|
86
86
|
# to be approximated by an 8-sided polygon. The exact behavior
|
87
87
|
# for different kinds of buffers is defined by GEOS.
|
88
|
-
# <tt>:srid</tt
|
88
|
+
# [<tt>:srid</tt>]
|
89
89
|
# Set the SRID returned by geometries created by this factory.
|
90
90
|
# Default is 0.
|
91
|
-
# <tt>:proj4</tt
|
91
|
+
# [<tt>:proj4</tt>]
|
92
92
|
# The coordinate system in Proj4 format, either as a
|
93
93
|
# CoordSys::Proj4 object or as a string or hash representing the
|
94
94
|
# proj4 format. Optional.
|
95
|
-
# <tt>:coord_sys</tt
|
95
|
+
# [<tt>:coord_sys</tt>]
|
96
96
|
# The coordinate system in OGC form, either as a subclass of
|
97
97
|
# CoordSys::CS::CoordinateSystem, or as a string in WKT format.
|
98
98
|
# Optional.
|
99
|
-
# <tt>:srs_database</tt
|
99
|
+
# [<tt>:srs_database</tt>]
|
100
100
|
# Optional. If provided, the value should be an implementation of
|
101
101
|
# CoordSys::SRSDatabase::Interface. If both this and an SRID are
|
102
102
|
# provided, they are used to look up the proj4 and coord_sys
|
103
103
|
# objects from a spatial reference system database.
|
104
|
-
# <tt>:has_z_coordinate</tt
|
104
|
+
# [<tt>:has_z_coordinate</tt>]
|
105
105
|
# Support <tt>z_coordinate</tt>. Default is false.
|
106
|
-
# <tt>:has_m_coordinate</tt
|
106
|
+
# [<tt>:has_m_coordinate</tt>]
|
107
107
|
# Support <tt>m_coordinate</tt>. Default is false.
|
108
108
|
|
109
109
|
def factory(opts_={})
|
@@ -53,7 +53,7 @@ module RGeo
|
|
53
53
|
# The following options are recognized. These can be passed to the
|
54
54
|
# constructor, or set on the object afterwards.
|
55
55
|
#
|
56
|
-
# <tt>:type_format</tt
|
56
|
+
# [<tt>:type_format</tt>]
|
57
57
|
# The format for type codes. Possible values are <tt>:wkb11</tt>,
|
58
58
|
# indicating SFS 1.1 WKB (i.e. no Z or M values); <tt>:ewkb</tt>,
|
59
59
|
# indicating the PostGIS EWKB extensions (i.e. Z and M presence
|
@@ -61,13 +61,13 @@ module RGeo
|
|
61
61
|
# embedded SRID); or <tt>:wkb12</tt> (indicating SFS 1.2 WKB
|
62
62
|
# (i.e. Z and M presence flagged by adding 1000 and/or 2000 to
|
63
63
|
# the type code.) Default is <tt>:wkb11</tt>.
|
64
|
-
# <tt>:emit_ewkb_srid</tt
|
64
|
+
# [<tt>:emit_ewkb_srid</tt>]
|
65
65
|
# If true, embed the SRID in the toplevel geometry. Available only
|
66
66
|
# if <tt>:type_format</tt> is <tt>:ewkb</tt>. Default is false.
|
67
|
-
# <tt>:hex_format</tt
|
67
|
+
# [<tt>:hex_format</tt>]
|
68
68
|
# If true, output a hex string instead of a byte string.
|
69
69
|
# Default is false.
|
70
|
-
# <tt>:little_endian</tt
|
70
|
+
# [<tt>:little_endian</tt>]
|
71
71
|
# If true, output little endian (NDR) byte order. If false, output
|
72
72
|
# big endian (XDR), or network byte order. Default is false.
|
73
73
|
|
@@ -58,19 +58,19 @@ module RGeo
|
|
58
58
|
# The following additional options are recognized. These can be passed
|
59
59
|
# to the constructor, or set on the object afterwards.
|
60
60
|
#
|
61
|
-
# <tt>:support_ewkb</tt
|
61
|
+
# [<tt>:support_ewkb</tt>]
|
62
62
|
# Activate support for PostGIS EWKB type codes, which use high
|
63
63
|
# order bits in the type code to signal the presence of Z, M, and
|
64
64
|
# SRID values in the data. Default is false.
|
65
|
-
# <tt>:support_wkb12</tt
|
65
|
+
# [<tt>:support_wkb12</tt>]
|
66
66
|
# Activate support for SFS 1.2 extensions to the type codes, which
|
67
67
|
# use values greater than 1000 to signal the presence of Z and M
|
68
68
|
# values in the data. SFS 1.2 types such as triangle, tin, and
|
69
69
|
# polyhedralsurface are NOT yet supported. Default is false.
|
70
|
-
# <tt>:ignore_extra_bytes</tt
|
70
|
+
# [<tt>:ignore_extra_bytes</tt>]
|
71
71
|
# If true, extra bytes at the end of the data are ignored. If
|
72
72
|
# false (the default), extra bytes will trigger a parse error.
|
73
|
-
# <tt>:default_srid</tt
|
73
|
+
# [<tt>:default_srid</tt>]
|
74
74
|
# A SRID to pass to the factory generator if no SRID is present in
|
75
75
|
# the input. Defaults to nil (i.e. don't specify a SRID).
|
76
76
|
|
@@ -52,7 +52,7 @@ module RGeo
|
|
52
52
|
# The following options are recognized. These can be passed to the
|
53
53
|
# constructor, or set on the object afterwards.
|
54
54
|
#
|
55
|
-
# <tt>:tag_format</tt
|
55
|
+
# [<tt>:tag_format</tt>]
|
56
56
|
# The format for tags. Possible values are <tt>:wkt11</tt>,
|
57
57
|
# indicating SFS 1.1 WKT (i.e. no Z or M markers in the tags) but
|
58
58
|
# with Z and/or M values added in if they are present;
|
@@ -63,13 +63,13 @@ module RGeo
|
|
63
63
|
# Z is present); or <tt>:wkt12</tt>, indicating SFS 1.2 WKT
|
64
64
|
# tags that indicate the presence of Z and M in a separate token.
|
65
65
|
# Default is <tt>:wkt11</tt>.
|
66
|
-
# <tt>:emit_ewkt_srid</tt
|
66
|
+
# [<tt>:emit_ewkt_srid</tt>]
|
67
67
|
# If true, embed the SRID of the toplevel geometry. Available only
|
68
68
|
# if <tt>:type_format</tt> is <tt>:ewkt</tt>. Default is false.
|
69
|
-
# <tt>:square_brackets</tt
|
69
|
+
# [<tt>:square_brackets</tt>]
|
70
70
|
# If true, uses square brackets rather than parentheses.
|
71
71
|
# Default is false.
|
72
|
-
# <tt>:convert_case</tt
|
72
|
+
# [<tt>:convert_case</tt>]
|
73
73
|
# Possible values are <tt>:upper</tt>, which changes all letters
|
74
74
|
# in the output to ALL CAPS; <tt>:lower</tt>, which changes all
|
75
75
|
# letters to lower case; or nil, indicating no case changes from
|
@@ -61,23 +61,23 @@ module RGeo
|
|
61
61
|
# The following additional options are recognized. These can be passed
|
62
62
|
# to the constructor, or set on the object afterwards.
|
63
63
|
#
|
64
|
-
# <tt>:support_ewkt</tt
|
64
|
+
# [<tt>:support_ewkt</tt>]
|
65
65
|
# Activate support for PostGIS EWKT type tags, which appends an "M"
|
66
66
|
# to tags to indicate the presence of M but not Z, and also
|
67
67
|
# recognizes the SRID prefix. Default is false.
|
68
|
-
# <tt>:support_wkt12</tt
|
68
|
+
# [<tt>:support_wkt12</tt>]
|
69
69
|
# Activate support for SFS 1.2 extensions to the type codes, which
|
70
70
|
# use a "M", "Z", or "ZM" token to signal the presence of Z and M
|
71
71
|
# values in the data. SFS 1.2 types such as triangle, tin, and
|
72
72
|
# polyhedralsurface are NOT yet supported. Default is false.
|
73
|
-
# <tt>:strict_wkt11</tt
|
73
|
+
# [<tt>:strict_wkt11</tt>]
|
74
74
|
# If true, parsing will proceed in SFS 1.1 strict mode, which
|
75
75
|
# disallows any values other than X or Y. This has no effect if
|
76
76
|
# support_ewkt or support_wkt12 are active. Default is false.
|
77
|
-
# <tt>:ignore_extra_tokens</tt
|
77
|
+
# [<tt>:ignore_extra_tokens</tt>]
|
78
78
|
# If true, extra tokens at the end of the data are ignored. If
|
79
79
|
# false (the default), extra tokens will trigger a parse error.
|
80
|
-
# <tt>:default_srid</tt
|
80
|
+
# [<tt>:default_srid</tt>]
|
81
81
|
# A SRID to pass to the factory generator if no SRID is present in
|
82
82
|
# the input. Defaults to nil (i.e. don't specify a SRID).
|
83
83
|
|
@@ -54,10 +54,13 @@ module RGeo
|
|
54
54
|
@point5 = @factory.point(-1, 2)
|
55
55
|
@point6 = @factory.point(-1, 1)
|
56
56
|
@point7 = @factory.point(5, 4)
|
57
|
+
@point8 = @factory.point(1, 3)
|
57
58
|
@horiz_seg = ::RGeo::Cartesian::Segment.new(@point1, @point3)
|
58
59
|
@vert_seg = ::RGeo::Cartesian::Segment.new(@point4, @point1)
|
59
60
|
@short_rising_seg = ::RGeo::Cartesian::Segment.new(@point1, @point2)
|
60
61
|
@long_rising_seg = ::RGeo::Cartesian::Segment.new(@point5, @point2)
|
62
|
+
@collinear_rising_seg = ::RGeo::Cartesian::Segment.new(@point5, @point8)
|
63
|
+
@touching_collinear_rising_seg = ::RGeo::Cartesian::Segment.new(@point1, @point8)
|
61
64
|
@parallel_rising_seg = ::RGeo::Cartesian::Segment.new(@point6, @point7)
|
62
65
|
@steep_rising_seg = ::RGeo::Cartesian::Segment.new(@point6, @point4)
|
63
66
|
@degenerate_seg = ::RGeo::Cartesian::Segment.new(@point5, @point5)
|
@@ -114,6 +117,10 @@ module RGeo
|
|
114
117
|
def test_segment_intersects_parallel
|
115
118
|
assert(@long_rising_seg.intersects_segment?(@long_rising_seg))
|
116
119
|
assert(!@long_rising_seg.intersects_segment?(@parallel_rising_seg))
|
120
|
+
assert(!@short_rising_seg.intersects_segment?(@collinear_rising_seg))
|
121
|
+
assert(@touching_collinear_rising_seg.intersects_segment?(@short_rising_seg))
|
122
|
+
assert(@touching_collinear_rising_seg.intersects_segment?(@long_rising_seg))
|
123
|
+
assert(@long_rising_seg.intersects_segment?(@touching_collinear_rising_seg))
|
117
124
|
end
|
118
125
|
|
119
126
|
|
metadata
CHANGED
@@ -1,12 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rgeo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 2
|
8
|
-
- 4
|
9
|
-
version: 0.2.4
|
4
|
+
prerelease:
|
5
|
+
version: 0.2.5
|
10
6
|
platform: ruby
|
11
7
|
authors:
|
12
8
|
- Daniel Azuma
|
@@ -14,7 +10,7 @@ autorequire:
|
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
12
|
|
17
|
-
date:
|
13
|
+
date: 2011-03-21 00:00:00 -07:00
|
18
14
|
default_executable:
|
19
15
|
dependencies: []
|
20
16
|
|
@@ -193,23 +189,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
193
189
|
requirements:
|
194
190
|
- - ">="
|
195
191
|
- !ruby/object:Gem::Version
|
196
|
-
segments:
|
197
|
-
- 1
|
198
|
-
- 8
|
199
|
-
- 7
|
200
192
|
version: 1.8.7
|
201
193
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
202
194
|
none: false
|
203
195
|
requirements:
|
204
196
|
- - ">="
|
205
197
|
- !ruby/object:Gem::Version
|
206
|
-
segments:
|
207
|
-
- 0
|
208
198
|
version: "0"
|
209
199
|
requirements: []
|
210
200
|
|
211
201
|
rubyforge_project: virtuoso
|
212
|
-
rubygems_version: 1.
|
202
|
+
rubygems_version: 1.6.2
|
213
203
|
signing_key:
|
214
204
|
specification_version: 3
|
215
205
|
summary: RGeo is a spatial data library for Ruby.
|