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