Quantcast
Channel: DotSpatial
Viewing all articles
Browse latest Browse all 3973

Created Unassigned: Error with decimal values and "," decimal separator no properties dialog [63612]

$
0
0
Using the properties Dialog to create Feature classes works fine until you use decimal values with dot as decimal separator.
If your decimal separator is a coma "," (European default) and the Expression has this value as FilterExpression you get an exception error.

There are 2 places where this error occurs:
DotSpatial.Symbology.FeatureLayer

```
public void AssignFastDrawnStates()
{
_drawnStatesNeeded = true;
_drawnStates = new FastDrawnState[DataSet.ShapeIndices.Count];
_selection.Changed -= SelectedFeaturesChanged;
_selection = new IndexSelection(this); // update the new drawn-states;
_selection.Changed += SelectedFeaturesChanged;

// Fastest when no categories are used because we don't need DataTable at all
List<IFeatureCategory> categories = _scheme.GetCategories().ToList();
IFeatureCategory deflt = null;
if (categories.Count > 0 && categories[0].FilterExpression == null)
{
deflt = categories[0];
}

for (int i = 0; i < DataSet.ShapeIndices.Count; i++)
{
_drawnStates[i] = new FastDrawnState { Category = deflt };
}

if (categories.Count == 1 && categories[0].FilterExpression == null)
{
return;
}

bool containsFid = false;
if (!DataSet.AttributesPopulated)
{
// We don't want to read the table multiple times for each category. Just
// read a block and then do all the categories we can for that block.
var names = new List<string>();
foreach (var category in categories)
{
var current = DistinctFieldsInExpression(category.FilterExpression);
foreach (string name in current.Where(name => !names.Contains(name)))
{
names.Add(name);
}
}

if (names.Count == 0)
{
for (int i = 0; i < DataSet.NumRows(); i++)
{
_drawnStates[i].Category = categories[categories.Count - 1];
}

return;
}

int rowCount = DataSet.NumRows();
const int size = 50000;
int numPages = (int)Math.Ceiling((double)rowCount / size);
for (int page = 0; page < numPages; page++)
{
int count = (page == numPages - 1) ? rowCount - page * size : size;
DataTable expressionTable = DataSet.GetAttributes(page * size, count, names);
foreach (var category in categories)
{
DataRow[] res = expressionTable.Select(category.FilterExpression);
foreach (DataRow r in res)
{
_drawnStates[(int)r["FID"]].Category = category;
}
}
}
}
else
{
DataTable table = DataSet.DataTable;
foreach (var category in categories)
{
if (category.FilterExpression != null && category.FilterExpression.Contains("[FID]"))
{
containsFid = true;
}
}

if (containsFid && table.Columns.Contains("FID") == false)
{
table.Columns.Add("FID");
for (int i = 0; i < table.Rows.Count; i++)
{
table.Rows[i]["FID"] = i;
}
}

foreach (var category in categories)
{

/// Changed
///
if (category.FilterExpression.Contains(","))
{
category.FilterExpression = category.FilterExpression.Replace(",", ".");
}
/// Changed
///
DataRow[] result = table.Select(category.FilterExpression);
foreach (DataRow row in result)
{
_drawnStates[table.Rows.IndexOf(row)].Category = category;
}
}

if (containsFid)
{
table.Columns.Remove("FID");
}
}
}
```
The second is the the DotSpatial.Data.FeatureSet

```
public virtual DataColumn[] GetColumns()
{
return (from DataColumn column in DataTable.Columns
select new DataColumn(column.ColumnName, column.DataType)).ToArray();
}

/// <inheritdoc/>
public virtual int[] GetCounts(string[] expressions, ICancelProgressHandler progressHandler, int maxSampleSize)
{
int[] counts = null;

if (expressions != null && expressions.Length > 0)
{
counts = new int[expressions.Length];
for (int i = 0; i < expressions.Length; i++)
{
if (expressions[i] != null)
{
if (expressions[i].Contains("=[NULL]"))
{
expressions[i] = expressions[i].Replace("=[NULL]", " is NULL");
}
else
if (expressions[i].Contains("= '[NULL]'"))
{
expressions[i] = expressions[i].Replace("= '[NULL]'", " is NULL");
}

/// Changed
///
if (expressions[i].Contains(","))
{
expressions[i] = expressions[i].Replace(",", ".");
}
/// Changed

}

counts[i] = DataTable.Select(expressions[i]).Length;

}
}

return counts;
}

```

My workarounds are marked with /// Changed

Please have a look if there is a better way to solve this Problem.

Thanks

Thomas

Viewing all articles
Browse latest Browse all 3973

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>