GEOS
3.6.2
|
00001 /********************************************************************** 00002 * 00003 * GEOS - Geometry Engine Open Source 00004 * http://geos.osgeo.org 00005 * 00006 * Copyright (C) 2011 Sandro Santilli <strk@keybit.net> 00007 * 00008 * This is free software; you can redistribute and/or modify it under 00009 * the terms of the GNU Lesser General Public Licence as published 00010 * by the Free Software Foundation. 00011 * See the COPYING file for more information. 00012 * 00013 ********************************************************************** 00014 * 00015 * Last port: linearref/LocationIndexedLine.java r466 00016 * 00017 **********************************************************************/ 00018 00019 #ifndef GEOS_LINEARREF_LOCATIONINDEXEDLINE_H 00020 #define GEOS_LINEARREF_LOCATIONINDEXEDLINE_H 00021 00022 #include <geos/export.h> 00023 #include <geos/geom/Coordinate.h> 00024 #include <geos/geom/Geometry.h> 00025 #include <geos/geom/Lineal.h> 00026 #include <geos/linearref/LinearLocation.h> 00027 #include <geos/linearref/LocationIndexOfPoint.h> 00028 #include <geos/linearref/LocationIndexOfLine.h> 00029 #include <geos/util/IllegalArgumentException.h> 00030 00031 namespace geos { 00032 namespace linearref { // geos::linearref 00033 00040 class GEOS_DLL LocationIndexedLine 00041 { 00042 private: 00043 const geom::Geometry *linearGeom; 00044 00045 void checkGeometryType() 00046 { 00047 if ( ! dynamic_cast<const geom::Lineal*>(linearGeom) ) 00048 throw util::IllegalArgumentException("Input geometry must be linear"); 00049 } 00050 00051 public: 00052 00060 LocationIndexedLine(const geom::Geometry *linearGeom) 00061 : linearGeom(linearGeom) 00062 { 00063 checkGeometryType(); 00064 } 00065 00079 geom::Coordinate extractPoint(const LinearLocation& index) const 00080 { 00081 return index.getCoordinate(linearGeom); 00082 } 00083 00084 00103 geom::Coordinate extractPoint(const LinearLocation& index, 00104 double offsetDistance) const 00105 { 00106 geom::Coordinate ret; 00107 index.getSegment(linearGeom)->pointAlongOffset( 00108 index.getSegmentFraction(), offsetDistance, ret 00109 ); 00110 return ret; 00111 } 00112 00125 geom::Geometry *extractLine(const LinearLocation& startIndex, 00126 const LinearLocation& endIndex) const 00127 { 00128 return ExtractLineByLocation::extract(linearGeom, startIndex, endIndex); 00129 } 00130 00131 00147 LinearLocation indexOf(const geom::Coordinate& pt) const 00148 { 00149 return LocationIndexOfPoint::indexOf(linearGeom, pt); 00150 } 00151 00176 LinearLocation indexOfAfter(const geom::Coordinate& pt, 00177 const LinearLocation& minIndex) const 00178 { 00179 return LocationIndexOfPoint::indexOfAfter(linearGeom, pt, &minIndex); 00180 } 00181 00193 LinearLocation* indicesOf(const geom::Geometry *subLine) const 00194 { 00195 return LocationIndexOfLine::indicesOf(linearGeom, subLine); 00196 } 00197 00198 00210 LinearLocation project(const geom::Coordinate& pt) const 00211 { 00212 return LocationIndexOfPoint::indexOf(linearGeom, pt); 00213 } 00214 00221 LinearLocation getStartIndex() const 00222 { 00223 return LinearLocation(); 00224 } 00225 00232 LinearLocation getEndIndex() const 00233 { 00234 return LinearLocation::getEndLocation(linearGeom); 00235 } 00236 00244 bool isValidIndex(const LinearLocation& index) const 00245 { 00246 return index.isValid(linearGeom); 00247 } 00248 00249 00257 LinearLocation clampIndex(const LinearLocation& index) const 00258 { 00259 LinearLocation loc = index; 00260 loc.clamp(linearGeom); 00261 return loc; 00262 } 00263 }; 00264 00265 } // geos::linearref 00266 } // geos 00267 #endif