Class InMemoryFeatureSource
This class represents a FeatureSource backed by memory, more specifically an in memory collection InternalFeatures.
public class InMemoryFeatureSource : FeatureSource
- Inheritance
-
InMemoryFeatureSource
- Inherited Members
Remarks
You can use this kind of FeatureSource when your InternalFeatures come from an external source which there is no FeatureSource specifically designed for it. An exmaple may be real time GPS locations. Another example might be location that a user selected by clicking on the screen.
Constructors
InMemoryFeatureSource()
public InMemoryFeatureSource()
InMemoryFeatureSource(IEnumerable<FeatureSourceColumn>)
Create a new instance of the InMemoryFeatureSource class.
public InMemoryFeatureSource(IEnumerable<FeatureSourceColumn> featureSourceColumns)
Parameters
featureSourceColumns
IEnumerable<FeatureSourceColumn>The featuresSourceColumns to instance the InMemoryFeatureSource.
Remarks
By calling this API to create a new instance of InMemoryFeatureSource, there will have no features in the created featureSource. After this, you can added the feature to the instance , and another even better opion is call another overloads constructor by passing the features too.
InMemoryFeatureSource(IEnumerable<FeatureSourceColumn>, IEnumerable<BaseShape>)
Create a new instance of the InMemoryFeatureSource class by passing a featureSourceColumns and an initial shapes to construct the shapes.
public InMemoryFeatureSource(IEnumerable<FeatureSourceColumn> featureSourceColumns, IEnumerable<BaseShape> shapes)
Parameters
featureSourceColumns
IEnumerable<FeatureSourceColumn>The featuresSourceColumns to instance the InMemoryFeatureSource.
shapes
IEnumerable<BaseShape>The shapes to contruct the features used to instance the InMemoryFeatureSource.
InMemoryFeatureSource(IEnumerable<FeatureSourceColumn>, IEnumerable<Feature>)
Create a new instance of the InMemoryFeatureSource class by passing a featureSourceColumns and an initial features.
public InMemoryFeatureSource(IEnumerable<FeatureSourceColumn> featureSourceColumns, IEnumerable<Feature> features)
Parameters
featureSourceColumns
IEnumerable<FeatureSourceColumn>The featuresSourceColumns to instance the InMemoryFeatureSource.
features
IEnumerable<Feature>The features to instance the InMemoryFeatureSource.
Properties
CanExecuteSqlQueryCore
protected override bool CanExecuteSqlQueryCore { get; }
Property Value
InternalFeatures
This property returns the underlying InternalFeatures stored in memory.
public GeoCollection<Feature> InternalFeatures { get; }
Property Value
Remarks
This property allows you to modify and inspect the InternalFeatures held by this FeatureSource in memory. You can use this as a quick way to add, update or remove InternalFeatures.
IsEditable
This property returns if the FeatureSource allows edits or is read only.
public override bool IsEditable { get; }
Property Value
Remarks
This property is useful to check if a specific FeatureSource accepts editing.
If you call the BeginTransaction and this property is false then an exception will
be raised.
For developers who are creating or extending a FeatureSource it is expected that
you override this virtual method if the new FeatureSource you are creating allows
edits. By default the decimalDegreesValue if false meaning that if you want to allow edits you
must override this method and return true.
Methods
BuildIndex()
This method build a spatial index for a passed group of featurs which increases access speed.
public void BuildIndex()
Clear()
This method will clear all the features included in the feature source.
public void Clear()
Exceptions
- InvalidOperationException
If you attempt to call this method on a feature source which is in a transaction, it will throw an InvalidOperationException.
- InvalidOperationException
If you attempt to call this method on a feature source which is not opened, it will throw an InvalidOperationException.
CommitTransactionCore(TransactionBuffer)
This method will commit the existing transaction to its underlying source of data.
protected override TransactionResult CommitTransactionCore(TransactionBuffer transactions)
Parameters
transactions
TransactionBufferThis parameter encapsulates all of the adds, edits and deleted that make up the transaction. You will use this data to write the changes to your underlying data source.
Returns
- TransactionResult
The return decimalDegreesValue of this method is a TransactionResult class which gives you the status of the transaction you just committed. It includes how many of the updates, adds, and deletes were successful and any error that were encountered during the committing of the transaction.
Remarks
This method will commit the existing transaction to its underlying source of data. It will pass back the results of how the commit went to include any error received. If you are implementing your own FeatureSource then this is one of the crucial methods you must create. It should be fairly straight forward that you will loop through the transaction buffer and add, edit or delete the InternalFeatures in your underlying data source. Remember to build and pass back the TransactionResult class so that users of your FeatureSource can respond to failures you may encounter committing the InternalFeatures. We will handle the end of the transaction and also the cleanup of the transaction buffer. Your task will be to commit the records and produce a TransactionResult return.
The Transaction System
The transaction system of a FeatureSource sits on top of the inherited implementation of any specific source such as Oracle Spatial or Shape files. In this way it functions the same way for every FeatureSource. You start by calling the BeginTransaction. This allocates a collection of in memory change buffers that are used to store changes until you commit the transaction. So for example when you call the Add, Delete or Update method the changes to the feature are stored in memory only. If for any reason you choose to abandon the transaction you can call RollbackTransaction at any time and the in memory buffer will be deleted and the changes will be lost. When you are ready to commit the transaction you call the CommitTransaction and the collections of changes are then passed to the CommitTransactionCore method and the implementer of the specific FeatureSource is responsible for integrating your changes into the underlying FeatureSource. By default the IsLiveTransaction property is set to false which means that until you commit the changes the FeatureSource API will not reflect any changes that are in the temporary editing buffer.
In the case where the IsLiveTransaction is set to true then things function slightly differently. The live transaction concept means that all of the modification you perform during a transaction are live from the standpoint of the querying methods on the object.
To setup an example imagine that you have a FeatureSource that has 10 records in it. Next you begin a transaction and then call GetAllFeatures, the result would be 10 records. After that you call a delete on one of the records and call the GetAllFeatures again, this time you only get nine records. You receive nine records even though the transaction has not yet been committed. In the same sense you could have added a new record or modified an existing one and those changes are considered live though not committed.
In the case where you modify records such as expanding the size of a polygon those changes as well are reflected. So for example you expand a polygon by doubling its size and then do a spatial query that would not normally return the smaller record but would return the larger records, in this case the larger record is returned. You can set this property to be false as well in which case all of the spatial related methods would ignore anything that is currently in the transaction buffer waiting to be committed. In this case only after committing the transaction would the FeatureSource reflect the changes.
Exceptions
- InvalidOperationException
In the event you attempt to call this method on a feature source which is not in transaction it will throw an InvalidOperationException.
GetAllFeaturesCore(IEnumerable<string>)
This method returns all of the InternalFeatures in the FeatureSource.
protected override Collection<Feature> GetAllFeaturesCore(IEnumerable<string> returningColumnNames)
Parameters
returningColumnNames
IEnumerable<string>This parameter allows you to select the field names of the column data you wish to return with each Feature.
Returns
- Collection<Feature>
The return decimalDegreesValue is a collection of all of the InternalFeatures in the FeatureSource.
Remarks
This method returns all of the InternalFeatures in the FeatureSource. You will not need
to consider anything about pending transactions as this will be handled in the non Core
version of the method.
The main purpose of this method is to be the anchor of all of our default virtual
implementations within this class. We wanted as the framework developers to provide you
the user with as much default virtual implementation as possible. To do this we needed
a way to get access to all of the features. For example, we want to create a default
implementation for finding all of the InternalFeatures in a bounding box. Because this is an
abstract class we do not know the specifics of the underlying data or how its spatial
indexes work. What we do know is that if we get all the records then we can brute force
the answer. In this way if you inherited form this class and only implemented this one
method we can provide default implementations for virtually every other API.
While this is nice for you the developer if you decide to create your own FeatureSource
it comes with a price. The price is that it is very inefficient. In the case we just
discussed about finding all of the InternalFeatures in a bounding box we would not want to look
at every record to fulfil this method. Instead we would want to override the
GetFeaturesInsideBoundingBoxCore and implement specific code that would be fast. For
example in Oracle Spatial there is a specific SQL statement to do this operation very
quickly. The same holds true with other specific FeatureSource examples.
Most default implementations in the FeatureSource call the
GetFeaturesInsideBoundingBoxCore which by default calls the GetAllFeaturesCore. It is
our advice that if you create your own FeatureSource that you ALWAYS override the
GetFeatureInsideBoundingBox. It will ensure that nearly every other API will operate
efficiently. Please see the specific API to determine what method it uses.
Exceptions
- InvalidOperationException
In the event you attempt to call this method on a feature source which has not been opened it will throw an InvalidOperationException.
GetAllFeaturesCore(IEnumerable<string>, int, int)
protected override Collection<Feature> GetAllFeaturesCore(IEnumerable<string> returningColumnNames, int startIndex, int takeCount)
Parameters
returningColumnNames
IEnumerable<string>startIndex
inttakeCount
int
Returns
GetColumnsCore()
This method returns the columns available for the FeatureSource.
protected override Collection<FeatureSourceColumn> GetColumnsCore()
Returns
- Collection<FeatureSourceColumn>
This method returns the columns available for the FeatureSource.
Remarks
When overriding you will be responsible for getting a list of all of the columns supported by the FeatureSource. In this way the FeatureSource will know what columns are available and will remove any extra columns when making calls to other core methods. For example if you have a FeatureSource that has three columns of information and the user calls a method and requests four columns of information, something they can do with custom fields, we will first compare what they are asking for to the results of the GetColumnsCore. In this way we can strip out custom columns before calling other Core methods which are only responsible for returning data in the FeatureSource. For more information on custom fields you can see the documentation on the OnCustomFieldsFetch.
Exceptions
- InvalidOperationException
In the event you attempt to call this method on a feature source which has not been opened it will throw an InvalidOperationException.
GetCountCore()
This method returns the count of the number of records in this FeatureSource.
protected override long GetCountCore()
Returns
- long
This method returns the count of the number of records in this FeatureSource.
Remarks
This protected virtual method is called from the concreate public method
GetCount. It does not take into account any transaction activity as this is the
responsibility of the concreate public method GetCount. In this way as a developer
if you choose to override this method you do not have to consider transaction at
all.
The default implementation of GetCountCore uses the GetAllRecordsCore method to
calculate how many records there are in the FeatureSource. We strongly recommend
that you provide your own implementation for this method that will be more
efficient
If you do not override this method the means it gets the count is by calling the
GetAllFeatureCore method and counting each feature. This is a very inefficient way
to get the count in most data sources. It is highly recommended that you override
this method and replace it with a highly optimized version. For example in a
ShapeFile the record count is in the main header of the file. Similarly if you are
using Oracle Spatial you can execute a simple query to get the count of all of the
record without returning them. In these ways you can greatly improve the
performance of this method.
Exceptions
- InvalidOperationException
If the operation is done under source closed state it will throw a InvalidOperationException.
GetFeaturesInsideBoundingBoxCore(RectangleShape, IEnumerable<string>)
This method returns all of the InternalFeatures of this FeatureSource that are inside of the specified bounding box.
protected override Collection<Feature> GetFeaturesInsideBoundingBoxCore(RectangleShape boundingBox, IEnumerable<string> returningColumnNames)
Parameters
boundingBox
RectangleShapeThis parameter represents the bounding box that you wish to find InternalFeatures inside of.
returningColumnNames
IEnumerable<string>This parameter allows you to select the field names of the column data that you wish to return with each Feature.
Returns
- Collection<Feature>
The returned decimalDegreesValue is a collection of all of the InternalFeatures that are inside of the bounding box.
Remarks
This method returns all of the InternalFeatures of this FeatureSource that are inside of the
specified bounding box. If you are overriding this method you will not need to consider
anything about transactions, as this is handled by the concrete version of this
method.
The default implementation of GetFeaturesInsideBoundingBoxCore uses the
GetAllRecordsCore method to determine which InternalFeatures are inside of the bounding box. We
strongly recommend that you provide your own implementation for this method that will
be more efficient. That is especially important for this method, as many other default
virtual methods use this for their calculations. When you override this method, we highly recommend
that you use any spatial indexes you have at your disposal to make this
method as fast as possible.
Exceptions
- InvalidOperationException
In the event you attempt to call this method on a feature source which has not been opened, it will throw an InvalidOperationException.
- ArgumentNullException
If you pass a null as the returningColumnNames, we will throw an ArgumentNullException.
- ArgumentNullException
If you pass a null as the boundingBox, we will throw an ArgumentNullException.
GetFeaturesOutsideBoundingBoxCore(RectangleShape, IEnumerable<string>)
This method returns all of the InternalFeatures of this FeatureSource outside of the specified bounding box.
protected override Collection<Feature> GetFeaturesOutsideBoundingBoxCore(RectangleShape boundingBox, IEnumerable<string> returningColumnNames)
Parameters
boundingBox
RectangleShapeThis parameter represents the bounding box that you wish to find InternalFeatures outside of.
returningColumnNames
IEnumerable<string>This parameter allows you to select the field names of the column data you wish to return with each Feature.
Returns
- Collection<Feature>
This method returns all of the InternalFeatures of this FeatureSource outside of the specified bounding box.
Remarks
This method returns all of the InternalFeatures of this FeatureSource outside of the
specified bounding box. If you are in a transaction and that transaction is live,
this method will also take that into consideration.
The default implementation of GetFeaturesOutsideBoundingBoxCore uses the
GetAllRecordsCore method to determine which InternalFeatures are outside of the bounding box.
We strongly recommend that you provide your own implementation for this method that
will be more efficient.
Exceptions
- InvalidOperationException
In the event you attempt to call this method on a feature source which has not been opened, it will throw an InvalidOperationException.
- ArgumentNullException
If you pass a null as the returningColumnNames, we will throw an ArgumentNullException.
- ArgumentNullException
If you pass a null as the boundingBox, we will throw an ArgumentNullException.