gooderp18绿色标准版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

751 satır
29KB

  1. /******************************************************************************
  2. * $Id: gnm.h c3122bfce67aa8278d0163c0d41cfe0ab05bd691 2019-03-23 21:38:44 +0100 Even Rouault $
  3. *
  4. * Project: GDAL/OGR Geography Network support (Geographic Network Model)
  5. * Purpose: GNM general public declarations.
  6. * Authors: Mikhail Gusev (gusevmihs at gmail dot com)
  7. * Dmitry Baryshnikov, polimax@mail.ru
  8. *
  9. ******************************************************************************
  10. * Copyright (c) 2014, Mikhail Gusev
  11. * Copyright (c) 2014-2015, NextGIS <info@nextgis.com>
  12. *
  13. * Permission is hereby granted, free of charge, to any person obtaining a
  14. * copy of this software and associated documentation files (the "Software"),
  15. * to deal in the Software without restriction, including without limitation
  16. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  17. * and/or sell copies of the Software, and to permit persons to whom the
  18. * Software is furnished to do so, subject to the following conditions:
  19. *
  20. * The above copyright notice and this permission notice shall be included
  21. * in all copies or substantial portions of the Software.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  24. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  25. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  26. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  27. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  28. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  29. * DEALINGS IN THE SOFTWARE.
  30. ****************************************************************************/
  31. #ifndef GNM
  32. #define GNM
  33. #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
  34. #include "ogrsf_frmts.h"
  35. #endif
  36. #include "gnmgraph.h"
  37. // Direction of an edge.
  38. typedef int GNMDirection; // We use int values in order to save them to the
  39. // network data.
  40. // Network's metadata parameters names.
  41. #define GNM_MD_NAME "net_name"
  42. #define GNM_MD_DESCR "net_description"
  43. #define GNM_MD_SRS "net_srs"
  44. #define GNM_MD_VERSION "net_version"
  45. #define GNM_MD_RULE "net_rule"
  46. #define GNM_MD_FORMAT "FORMAT"
  47. #define GNM_MD_FETCHEDGES "fetch_edge"
  48. #define GNM_MD_FETCHVERTEX "fetch_vertex"
  49. #define GNM_MD_NUM_PATHS "num_paths"
  50. #define GNM_MD_EMITTER "emitter"
  51. // TODO: Constants for capabilities.
  52. //#define GNMCanChangeConnections "CanChangeConnections"
  53. typedef enum
  54. {
  55. /** Dijkstra shortest path */ GATDijkstraShortestPath = 1,
  56. /** KShortest Paths */ GATKShortestPath,
  57. /** Recursive Breadth-first search */ GATConnectedComponents
  58. } GNMGraphAlgorithmType;
  59. #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
  60. /**
  61. * General GNM class which represents a geography network of common format.
  62. *
  63. * @since GDAL 2.1
  64. */
  65. class CPL_DLL GNMNetwork : public GDALDataset
  66. {
  67. public:
  68. GNMNetwork();
  69. virtual ~GNMNetwork();
  70. // GDALDataset Interface
  71. const OGRSpatialReference* GetSpatialRef() const override {
  72. return GetSpatialRefFromOldGetProjectionRef();
  73. }
  74. virtual char **GetFileList(void) override;
  75. // GNMNetwork Interface
  76. /**
  77. * @brief Create network system layers
  78. *
  79. * Creates the connectivity (the "network path" of data) over the dataset
  80. * and returns the resulting network.
  81. * NOTE: This method does not create any connections among features
  82. * but creates the necessary set of fields, layers, etc.
  83. * NOTE: After the successful creation the passed dataset must not be
  84. * modified outside (but can be read as usual).
  85. * NOTE: For the common network format the creation is forbidden if the
  86. * passed dataset already has network system layers and OVERWRITE creation
  87. * option is FALSE.
  88. *
  89. * @param pszFilename - A path there the network folder (schema, etc.) will
  90. * be created. The folder (schema, etc.) name get
  91. * options.
  92. * @param papszOptions - create network options. The create options
  93. * specific for gnm driver.
  94. * @return CE_None on success
  95. */
  96. virtual CPLErr Create( const char* pszFilename, char** papszOptions ) = 0;
  97. /**
  98. * @brief Open a network
  99. * @param poOpenInfo GDALOpenInfo pointer
  100. * @return CE_None on success
  101. */
  102. virtual CPLErr Open( GDALOpenInfo* poOpenInfo ) = 0;
  103. /**
  104. * @brief Delete network. Delete all dependent layers
  105. * @return CE_None on success
  106. */
  107. virtual CPLErr Delete() = 0;
  108. /**
  109. * @brief GetName - a network name. The value provided to create function
  110. * in GNM_MD_NAME key. While creation this value used to create the
  111. * folder or db schema name. But can be changed after creation.
  112. * @return Network name string
  113. */
  114. virtual const char* GetName() const;
  115. /**
  116. * @brief GetVersion return the network version if applicable
  117. * @return version value
  118. */
  119. virtual int GetVersion() const { return 0;}
  120. /**
  121. * @brief DisconnectAll method clears the network graph
  122. * @return CE_None on success
  123. */
  124. virtual CPLErr DisconnectAll () = 0;
  125. /**
  126. * @brief GetFeatureByGlobalFID search all network layers for given feature
  127. * identificator.
  128. * @param nGFID feature identificator.
  129. * @return OGRFeature pointer or NULL. The pointer should be freed via
  130. * OGRFeature::DestroyFeature().
  131. */
  132. virtual OGRFeature *GetFeatureByGlobalFID (GNMGFID nGFID) = 0;
  133. /**
  134. * @brief Create path between start and end GFIDs.
  135. * @param nStartFID - start identificator
  136. * @param nEndFID - end identificator
  137. * @param eAlgorithm - The algorithm to get path
  138. * @param papszOptions - algorithm specific options
  139. * @return In memory OGRLayer pointer with features constituting
  140. * the shortest path (or paths). The caller have to free
  141. * the pointer via @see ReleaseResultSet().
  142. */
  143. virtual OGRLayer *GetPath (GNMGFID nStartFID, GNMGFID nEndFID,
  144. GNMGraphAlgorithmType eAlgorithm, char** papszOptions) = 0;
  145. protected:
  146. /**
  147. * @brief Check if network already exist
  148. * @param pszFilename - path to network (folder or database
  149. * @param papszOptions - create options
  150. * @return TRUE if exist and not overwrite or FALSE
  151. */
  152. virtual int CheckNetworkExist( const char* pszFilename,
  153. char** papszOptions ) = 0;
  154. //! @cond Doxygen_Suppress
  155. const char *_GetProjectionRef(void) override;
  156. //! @endcond
  157. protected:
  158. //! @cond Doxygen_Suppress
  159. CPLString m_soName;
  160. CPLString m_soSRS;
  161. //! @endcond
  162. };
  163. class GNMRule;
  164. class OGRGNMWrappedResultLayer;
  165. /**
  166. * GNM class which represents a geography network of generic format.
  167. *
  168. * @since GDAL 2.1
  169. */
  170. class CPL_DLL GNMGenericNetwork: public GNMNetwork
  171. {
  172. public:
  173. GNMGenericNetwork();
  174. virtual ~GNMGenericNetwork();
  175. // GDALDataset Interface
  176. virtual int GetLayerCount() override;
  177. virtual OGRLayer *GetLayer(int) override;
  178. virtual OGRErr DeleteLayer(int) override;
  179. virtual int TestCapability( const char * ) override;
  180. virtual OGRLayer *CopyLayer( OGRLayer *poSrcLayer,
  181. const char *pszNewName,
  182. char **papszOptions = nullptr ) override;
  183. virtual int CloseDependentDatasets() override;
  184. virtual void FlushCache(void) override;
  185. // GNMNetwork Interface
  186. virtual CPLErr Create( const char* pszFilename, char** papszOptions ) override = 0;
  187. virtual CPLErr Delete() override;
  188. virtual int GetVersion() const override;
  189. /**
  190. * @brief GetNewGlobalFID increase the global ID counter.
  191. * @return New global feature ID.
  192. */
  193. virtual GNMGFID GetNewGlobalFID();
  194. /**
  195. * @brief Get the algorithm name
  196. * @param eAlgorithm GNM algorithm type
  197. * @param bShortName Indicator which name to return - short or long
  198. * @return String with algorithm name
  199. */
  200. virtual CPLString GetAlgorithmName(GNMDirection eAlgorithm, bool bShortName);
  201. /**
  202. * @brief AddFeatureGlobalFID add the FID <-> Layer name link to fast access
  203. * features by global FID.
  204. * @param nFID - global FID
  205. * @param pszLayerName - layer name
  206. * @return CE_None on success
  207. */
  208. virtual CPLErr AddFeatureGlobalFID(GNMGFID nFID, const char* pszLayerName);
  209. /**
  210. * @brief Connects two features via third feature (may be virtual, so the
  211. * identificator should be -1). The features may be at the same layer
  212. * or different layers.
  213. * @param nSrcFID - source feature identificator
  214. * @param nTgtFID - target feature identificator
  215. * @param nConFID - connection feature identificator (-1 for virtual connection)
  216. * @param dfCost - cost moving from source to target (default 1)
  217. * @param dfInvCost - cost moving from target to source (default 1)
  218. * @param eDir - direction, may be source to target, traget to source or both.
  219. * (default - both)
  220. * @return CE_None on success
  221. */
  222. virtual CPLErr ConnectFeatures (GNMGFID nSrcFID,
  223. GNMGFID nTgtFID,
  224. GNMGFID nConFID = -1,
  225. double dfCost = 1,
  226. double dfInvCost = 1,
  227. GNMDirection eDir = GNM_EDGE_DIR_BOTH);
  228. /**
  229. * @brief Remove features connection
  230. * @param nSrcFID - source feature identificator
  231. * @param nTgtFID - target feature identificator
  232. * @param nConFID - connection feature identificator
  233. * @return CE_None on success
  234. */
  235. virtual CPLErr DisconnectFeatures (GNMGFID nSrcFID,
  236. GNMGFID nTgtFID,
  237. GNMGFID nConFID);
  238. /**
  239. * @brief Find the corresponding identificator in graph (source, target,
  240. * connector) and remove such connections.
  241. * @param nFID - identificator to find.
  242. * @return CE_None on success
  243. */
  244. virtual CPLErr DisconnectFeaturesWithId(GNMGFID nFID);
  245. /**
  246. * @brief Change connection attributes. Search the connection by source
  247. * feature identificator, target feature identificator and connection
  248. * identificator.
  249. * @param nSrcFID - source feature identificator
  250. * @param nTgtFID - target feature identificator
  251. * @param nConFID - connection feature identificator
  252. * @param dfCost - new cost moving from source to target
  253. * @param dfInvCost - new cost moving from target to source
  254. * @param eDir - new direction
  255. * @return CE_None on success
  256. */
  257. virtual CPLErr ReconnectFeatures (GNMGFID nSrcFID,
  258. GNMGFID nTgtFID,
  259. GNMGFID nConFID,
  260. double dfCost = 1,
  261. double dfInvCost = 1,
  262. GNMDirection eDir = GNM_EDGE_DIR_BOTH);
  263. virtual CPLErr DisconnectAll() override;
  264. virtual OGRFeature *GetFeatureByGlobalFID(GNMGFID nFID) override;
  265. /**
  266. * @brief Create network rule
  267. *
  268. * Creates the rule in the network according to the special syntax. These
  269. * rules are declarative and make an effect for the network when they exist.
  270. * Each rule for layer can be created only if the corresponding layer
  271. * existed and removed when the layer is being deleted.
  272. *
  273. * Rules syntax for the common network format in GNM contains the key words
  274. * (words in capital letters or signs) and the modifiers which refers to the
  275. * network objects. All the following combinations are available:
  276. *
  277. * Notation:
  278. * layer1, layer2, layer3 - a layer names (the corresponding layers must be
  279. * exist;
  280. * field1 - a field name (field must be exist);
  281. * constant1 - any double constant;
  282. * string1 - any string;
  283. *
  284. * Rules describing which layer can be connected or not connected with each
  285. * other, and (optional) which layer must serve as a connector. By default
  286. * all connections are forbidden. But while network creation process the
  287. * rule to allow any connection added. During the connection process each
  288. * rule tested if this connection can be created.
  289. *
  290. * "ALLOW CONNECTS ANY"
  291. * "DENY CONNECTS ANY"
  292. * "DENY CONNECTS layer1 WITH layer2"
  293. * "ALLOW CONNECTS layer1 WITH layer2 VIA layer3"
  294. *
  295. * @param pszRuleStr Rule string which will parsed. If the parsing was
  296. * successful, the rule will start having effect immediately.
  297. * @return CE_None on success.
  298. */
  299. virtual CPLErr CreateRule (const char *pszRuleStr);
  300. /**
  301. * @brief Delete all rules from network
  302. * @return CE_None on success.
  303. */
  304. virtual CPLErr DeleteAllRules();
  305. /**
  306. * @brief Delete the specified rule
  307. * @param pszRuleStr - the rule to delete
  308. * @return CE_None on success.
  309. */
  310. virtual CPLErr DeleteRule(const char *pszRuleStr);
  311. /**
  312. * @brief Get the rule list
  313. * @return list of rule strings. The caller have to free the lis via CPLDestroy.
  314. */
  315. virtual char** GetRules() const;
  316. /**
  317. * @brief Attempts to build the network topology automatically
  318. *
  319. * The method simply gets point and line or multiline layers from the
  320. * papszLayerList and searches for each line which connects two points: start
  321. * and end, so it can be not so effective in performance when it is called
  322. * on huge networks.
  323. * Note, when passing your tolerance value: this value will depend of spatial
  324. * reference system of the network, and especially of its 0,0 position
  325. * because dfTolerance is just divided by 2 and added/subtracted to/from
  326. * both sides of each line-feature end point forming thus the square area
  327. * around it. The first point-feature occurred inside this area will be given
  328. * as a start/end point for the current connection. So it is also desirable
  329. * that at least two layers are passed in papszLayerList (one point and one
  330. * line), and they are already connected "visually" ("geometrically").
  331. *
  332. * @param papszLayerList A list of layers to connect. The list should be
  333. * freed via CSLDestroy.
  334. * @param dfTolerance Snapping tolerance.
  335. * @param dfCost Direct cost.
  336. * @param dfInvCost Inverse cost.
  337. * @param eDir Direction.
  338. * @return CE_None on success
  339. */
  340. virtual CPLErr ConnectPointsByLines (char **papszLayerList,
  341. double dfTolerance,
  342. double dfCost,
  343. double dfInvCost,
  344. GNMDirection eDir);
  345. /**
  346. * @brief Change the block state of edge or vertex
  347. * @param nFID Identificator
  348. * @param bIsBlock Block or unblock
  349. * @return CE_None on success
  350. */
  351. virtual CPLErr ChangeBlockState (GNMGFID nFID, bool bIsBlock);
  352. /**
  353. * @brief Change all vertices and edges block state.
  354. *
  355. * This is mainly use for unblock all vertices and edges.
  356. *
  357. * @param bIsBlock Block or unblock
  358. * @return CE_None on success
  359. */
  360. virtual CPLErr ChangeAllBlockState (bool bIsBlock = false);
  361. virtual OGRLayer *GetPath (GNMGFID nStartFID, GNMGFID nEndFID,
  362. GNMGraphAlgorithmType eAlgorithm, char** papszOptions) override;
  363. protected:
  364. /**
  365. * @brief Check or create layer OGR driver
  366. * @param pszDefaultDriverName - default driver name
  367. * @param papszOptions - create options
  368. * @return CE_None if driver is exist or CE_Failure
  369. */
  370. virtual CPLErr CheckLayerDriver(const char* pszDefaultDriverName,
  371. char** papszOptions);
  372. /**
  373. * @brief Check if provided OGR driver accepted as storage for network data
  374. * @param pszDriverName The driver name
  375. * @return true if supported, else false
  376. */
  377. virtual bool CheckStorageDriverSupport(const char* pszDriverName) = 0;
  378. protected:
  379. //! @cond Doxygen_Suppress
  380. virtual CPLErr CreateMetadataLayer( GDALDataset* const pDS, int nVersion,
  381. size_t nFieldSize = 1024 );
  382. virtual CPLErr StoreNetworkSrs();
  383. virtual CPLErr LoadNetworkSrs();
  384. virtual CPLErr CreateGraphLayer( GDALDataset* const pDS );
  385. virtual CPLErr CreateFeaturesLayer( GDALDataset* const pDS );
  386. virtual CPLErr LoadMetadataLayer( GDALDataset* const pDS );
  387. virtual CPLErr LoadGraphLayer( GDALDataset* const pDS );
  388. virtual CPLErr LoadGraph();
  389. virtual CPLErr LoadFeaturesLayer( GDALDataset* const pDS );
  390. virtual CPLErr DeleteMetadataLayer() = 0;
  391. virtual CPLErr DeleteGraphLayer() = 0;
  392. virtual CPLErr DeleteFeaturesLayer() = 0;
  393. virtual CPLErr LoadNetworkLayer(const char* pszLayername) = 0;
  394. virtual CPLErr DeleteNetworkLayers() = 0;
  395. virtual void ConnectPointsByMultiline(GIntBig nFID,
  396. const OGRMultiLineString *poMultiLineString,
  397. const std::vector<OGRLayer *> &paPointLayers,
  398. double dfTolerance, double dfCost,
  399. double dfInvCost, GNMDirection eDir);
  400. virtual void ConnectPointsByLine(GIntBig nFID,
  401. const OGRLineString *poLineString,
  402. const std::vector<OGRLayer *> &paPointLayers,
  403. double dfTolerance, double dfCost,
  404. double dfInvCost, GNMDirection eDir);
  405. virtual GNMGFID FindNearestPoint(const OGRPoint* poPoint,
  406. const std::vector<OGRLayer*>& paPointLayers,
  407. double dfTolerance);
  408. virtual OGRFeature* FindConnection(GNMGFID nSrcFID, GNMGFID nTgtFID,
  409. GNMGFID nConFID);
  410. virtual void SaveRules();
  411. virtual GNMGFID GetNewVirtualFID();
  412. virtual void FillResultLayer(OGRGNMWrappedResultLayer* poResLayer,
  413. const GNMPATH &path, int nNoOfPath,
  414. bool bReturnVertices, bool bReturnEdges);
  415. //! @endcond
  416. protected:
  417. //! @cond Doxygen_Suppress
  418. int m_nVersion;
  419. GNMGFID m_nGID;
  420. GNMGFID m_nVirtualConnectionGID;
  421. OGRLayer* m_poMetadataLayer;
  422. OGRLayer* m_poGraphLayer;
  423. OGRLayer* m_poFeaturesLayer;
  424. GDALDriver *m_poLayerDriver;
  425. std::map<GNMGFID, CPLString> m_moFeatureFIDMap;
  426. std::vector<OGRLayer*> m_apoLayers;
  427. std::vector<GNMRule> m_asRules;
  428. bool m_bIsRulesChanged;
  429. GNMGraph m_oGraph;
  430. bool m_bIsGraphLoaded;
  431. //! @endcond
  432. };
  433. /**
  434. * GNM layer which represents a geography network layer of generic format.
  435. * The class override some OGRLayer methods to fulfill the network requirements.
  436. *
  437. * @since GDAL 2.1
  438. */
  439. class GNMGenericLayer : public OGRLayer
  440. {
  441. public:
  442. GNMGenericLayer(OGRLayer* poLayer, GNMGenericNetwork* poNetwork);
  443. virtual ~GNMGenericLayer();
  444. // OGRLayer Interface
  445. virtual OGRGeometry *GetSpatialFilter() override;
  446. virtual void SetSpatialFilter( OGRGeometry * ) override;
  447. virtual void SetSpatialFilterRect( double dfMinX, double dfMinY,
  448. double dfMaxX, double dfMaxY ) override;
  449. virtual void SetSpatialFilter( int iGeomField, OGRGeometry * ) override;
  450. virtual void SetSpatialFilterRect( int iGeomField,
  451. double dfMinX, double dfMinY,
  452. double dfMaxX, double dfMaxY ) override;
  453. virtual OGRErr SetAttributeFilter( const char * ) override;
  454. virtual void ResetReading() override;
  455. virtual OGRFeature *GetNextFeature() override;
  456. virtual OGRErr SetNextByIndex( GIntBig nIndex ) override;
  457. virtual OGRErr DeleteFeature( GIntBig nFID ) override;
  458. virtual const char *GetName() override;
  459. virtual OGRwkbGeometryType GetGeomType() override;
  460. virtual OGRFeatureDefn *GetLayerDefn() override;
  461. virtual int FindFieldIndex( const char *pszFieldName, int bExactMatch ) override;
  462. virtual OGRSpatialReference *GetSpatialRef() override;
  463. virtual GIntBig GetFeatureCount( int bForce = TRUE ) override;
  464. virtual OGRErr GetExtent(OGREnvelope *psExtent, int bForce = TRUE) override;
  465. virtual OGRErr GetExtent(int iGeomField, OGREnvelope *psExtent,
  466. int bForce = TRUE) override;
  467. virtual int TestCapability( const char * ) override;
  468. virtual OGRErr CreateField( OGRFieldDefn *poField,
  469. int bApproxOK = TRUE ) override;
  470. virtual OGRErr DeleteField( int iField ) override;
  471. virtual OGRErr ReorderFields( int* panMap ) override;
  472. virtual OGRErr AlterFieldDefn( int iField, OGRFieldDefn* poNewFieldDefn,
  473. int nFlagsIn ) override;
  474. virtual OGRErr CreateGeomField( OGRGeomFieldDefn *poField,
  475. int bApproxOK = TRUE ) override;
  476. virtual OGRErr SyncToDisk() override;
  477. virtual OGRStyleTable *GetStyleTable() override;
  478. virtual void SetStyleTableDirectly( OGRStyleTable *poStyleTable ) override;
  479. virtual void SetStyleTable(OGRStyleTable *poStyleTable) override;
  480. virtual OGRErr StartTransaction() override;
  481. virtual OGRErr CommitTransaction() override;
  482. virtual OGRErr RollbackTransaction() override;
  483. virtual const char *GetFIDColumn() override;
  484. virtual const char *GetGeometryColumn() override;
  485. virtual OGRErr SetIgnoredFields( const char **papszFields ) override;
  486. /** Intersection */
  487. OGRErr Intersection( OGRLayer *pLayerMethod,
  488. OGRLayer *pLayerResult,
  489. char** papszOptions = nullptr,
  490. GDALProgressFunc pfnProgress = nullptr,
  491. void * pProgressArg = nullptr );
  492. /** Union */
  493. OGRErr Union( OGRLayer *pLayerMethod,
  494. OGRLayer *pLayerResult,
  495. char** papszOptions = nullptr,
  496. GDALProgressFunc pfnProgress = nullptr,
  497. void * pProgressArg = nullptr );
  498. /** SymDifference */
  499. OGRErr SymDifference( OGRLayer *pLayerMethod,
  500. OGRLayer *pLayerResult,
  501. char** papszOptions,
  502. GDALProgressFunc pfnProgress,
  503. void * pProgressArg );
  504. /** Identity */
  505. OGRErr Identity( OGRLayer *pLayerMethod,
  506. OGRLayer *pLayerResult,
  507. char** papszOptions = nullptr,
  508. GDALProgressFunc pfnProgress = nullptr,
  509. void * pProgressArg = nullptr );
  510. /** Update */
  511. OGRErr Update( OGRLayer *pLayerMethod,
  512. OGRLayer *pLayerResult,
  513. char** papszOptions = nullptr,
  514. GDALProgressFunc pfnProgress = nullptr,
  515. void * pProgressArg = nullptr );
  516. /** Clip */
  517. OGRErr Clip( OGRLayer *pLayerMethod,
  518. OGRLayer *pLayerResult,
  519. char** papszOptions = nullptr,
  520. GDALProgressFunc pfnProgress = nullptr,
  521. void * pProgressArg = nullptr );
  522. /** Erase */
  523. OGRErr Erase( OGRLayer *pLayerMethod,
  524. OGRLayer *pLayerResult,
  525. char** papszOptions = nullptr,
  526. GDALProgressFunc pfnProgress = nullptr,
  527. void * pProgressArg = nullptr );
  528. /** GetFeaturesRead */
  529. GIntBig GetFeaturesRead();
  530. /** AttributeFilterEvaluationNeedsGeometry */
  531. int AttributeFilterEvaluationNeedsGeometry();
  532. //! @cond Doxygen_Suppress
  533. /* consider these private */
  534. OGRErr InitializeIndexSupport( const char * );
  535. OGRLayerAttrIndex *GetIndex();
  536. //! @endcond
  537. protected:
  538. //! @cond Doxygen_Suppress
  539. virtual OGRErr ISetFeature( OGRFeature *poFeature ) override;
  540. virtual OGRErr ICreateFeature( OGRFeature *poFeature ) override;
  541. protected:
  542. CPLString m_soLayerName;
  543. OGRLayer *m_poLayer;
  544. GNMGenericNetwork* m_poNetwork;
  545. std::map<GNMGFID, GIntBig> m_mnFIDMap;
  546. //! @endcond
  547. };
  548. typedef enum
  549. {
  550. /** Rule for connect features */ GRTConnection = 0
  551. } GNMRuleType;
  552. /**
  553. * @brief The simple class for rules
  554. *
  555. * By now we have only connect rules, so the one class is enough. Maybe in
  556. * future the set of classes for different rule types will be needed.
  557. *
  558. * @since GDAL 2.1
  559. */
  560. class CPL_DLL GNMRule
  561. {
  562. public:
  563. /** Constructor */
  564. GNMRule();
  565. /** Constructor */
  566. explicit GNMRule(const std::string &oRule );
  567. /** Constructor */
  568. explicit GNMRule(const char* pszRule);
  569. /** Constructor */
  570. GNMRule(const GNMRule &oRule);
  571. /** Assignment operator */
  572. GNMRule& operator=(const GNMRule&) = default;
  573. virtual ~GNMRule();
  574. /**
  575. * @brief This function indicate if rule string was parsed successfully
  576. * @return true if rule is valid
  577. */
  578. virtual bool IsValid() const;
  579. /**
  580. * @brief Indicator of any layer state
  581. * @return true if accept any layer
  582. */
  583. virtual bool IsAcceptAny() const;
  584. /**
  585. * @brief This is for future use to indicate the rule type/ Now return only
  586. * GRTConnection type.
  587. * @return the rule type
  588. */
  589. virtual GNMRuleType GetType() const;
  590. /**
  591. * @brief Check if connection can take place.
  592. * @param soSrcLayerName - the layer name
  593. * @param soTgtLayerName - the layer name
  594. * @param soConnLayerName - the layer name
  595. * @return true if can connect features from soSrcLayerName and soTgtLayerName
  596. * via soConnLayerName
  597. */
  598. virtual bool CanConnect(const CPLString &soSrcLayerName,
  599. const CPLString &soTgtLayerName,
  600. const CPLString &soConnLayerName = "");
  601. /** Return source layer name */
  602. virtual CPLString GetSourceLayerName() const;
  603. /** Return target layer name */
  604. virtual CPLString GetTargetLayerName() const;
  605. /** Return connector layer name */
  606. virtual CPLString GetConnectorLayerName() const;
  607. /** Return rule as a string */
  608. const char* c_str() const;
  609. /** Return rule as a string */
  610. operator const char* (void) const;
  611. protected:
  612. //! @cond Doxygen_Suppress
  613. virtual bool ParseRuleString();
  614. protected:
  615. CPLString m_soSrcLayerName;
  616. CPLString m_soTgtLayerName;
  617. CPLString m_soConnLayerName;
  618. bool m_bAllow;
  619. bool m_bValid;
  620. bool m_bAny;
  621. CPLString m_soRuleString;
  622. //! @endcond
  623. };
  624. /**
  625. * @brief The OGRGNMWrappedResultLayer class for search paths queries results.
  626. *
  627. * @since GDAL 2.1
  628. */
  629. class OGRGNMWrappedResultLayer : public OGRLayer
  630. {
  631. public:
  632. OGRGNMWrappedResultLayer(GDALDataset* poDS, OGRLayer* poLayer);
  633. ~OGRGNMWrappedResultLayer();
  634. // OGRLayer
  635. virtual void ResetReading() override;
  636. virtual OGRFeature *GetNextFeature() override;
  637. virtual OGRErr SetNextByIndex( GIntBig nIndex ) override;
  638. virtual OGRFeature *GetFeature( GIntBig nFID ) override;
  639. virtual OGRFeatureDefn *GetLayerDefn() override;
  640. virtual GIntBig GetFeatureCount( int bForce = TRUE ) override;
  641. virtual int TestCapability( const char * pszCap ) override;
  642. virtual OGRErr CreateField( OGRFieldDefn *poField, int bApproxOK = TRUE ) override;
  643. virtual OGRErr CreateGeomField( OGRGeomFieldDefn *poField,
  644. int bApproxOK = TRUE ) override;
  645. virtual const char *GetFIDColumn() override;
  646. virtual const char *GetGeometryColumn() override;
  647. virtual OGRSpatialReference *GetSpatialRef() override;
  648. // OGRGNMWrappedResultLayer
  649. virtual OGRErr InsertFeature(OGRFeature* poFeature,
  650. const CPLString &soLayerName, int nPathNo,
  651. bool bIsEdge);
  652. protected:
  653. virtual OGRErr ISetFeature( OGRFeature *poFeature ) override;
  654. virtual OGRErr ICreateFeature( OGRFeature *poFeature ) override;
  655. protected:
  656. //! @cond Doxygen_Suppress
  657. GDALDataset *poDS;
  658. OGRLayer *poLayer;
  659. //! @endcond
  660. };
  661. #endif // __cplusplus
  662. #endif // GNM
上海开阖软件有限公司 沪ICP备12045867号-1