| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent aa3394a commit ce2b57f
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -58,8 +58,9 @@ namespace SharpMap.Data.Providers | |||
| 58 | 58 | /// </remarks> | |
| 59 | 59 | public class GeometryFeatureProvider : FilterProvider, IProvider | |
| 60 | 60 | { | |
| 61 | + private readonly object _featuresLock = new object(); | ||
| 61 | 62 | private readonly FeatureDataTable _features; | |
| 62 | - private int _SRID = -1; | ||
| 63 | + private int _srid = -1; | ||
| 63 | 64 | ||
| 64 | 65 | #region constructors | |
| 65 | 66 | ||
@@ -115,7 +116,13 @@ private void HandleFeaturesCleared(object sender, DataTableClearEventArgs e) | |||
| 115 | 116 | /// </summary> | |
| 116 | 117 | public FeatureDataTable Features | |
| 117 | 118 | { | |
| 118 | - get { return _features; } | ||
| 119 | + get | ||
| 120 | + { | ||
| 121 | + lock (_features) | ||
| 122 | + { | ||
| 123 | + return _features; | ||
| 124 | + } | ||
| 125 | + } | ||
| 119 | 126 | } | |
| 120 | 127 | ||
| 121 | 128 | #region IProvider Members | |
@@ -129,14 +136,43 @@ public Collection<IGeometry> GetGeometriesInView(Envelope bbox) | |||
| 129 | 136 | { | |
| 130 | 137 | var list = new Collection<IGeometry>(); | |
| 131 | 138 | ||
| 132 | - foreach (FeatureDataRow fdr in _features.Rows) | ||
| 133 | - if (!fdr.Geometry.IsEmpty) | ||
| 134 | - if (FilterDelegate == null || FilterDelegate(fdr)) | ||
| 139 | + lock (_features) | ||
| 140 | + { | ||
| 141 | + foreach (FeatureDataRow fdr in _features.Rows) | ||
| 142 | + if (!fdr.Geometry.IsEmpty) | ||
| 143 | + if (FilterDelegate == null || FilterDelegate(fdr)) | ||
| 144 | + { | ||
| 145 | + if (bbox.Intersects(fdr.Geometry.EnvelopeInternal)) | ||
| 146 | + list.Add(fdr.Geometry); | ||
| 147 | + } | ||
| 148 | + } | ||
| 149 | + return list; | ||
| 150 | + } | ||
| 151 | + | ||
| 152 | + private IEnumerable<KeyValuePair<uint, FeatureDataRow>> EnumerateFeatures(Envelope bbox) | ||
| 153 | + { | ||
| 154 | + lock (_featuresLock) | ||
| 155 | + { | ||
| 156 | + uint id = 0; | ||
| 157 | + if (FilterDelegate == null) | ||
| 158 | + foreach (FeatureDataRow feature in _features.Rows) | ||
| 135 | 159 | { | |
| 136 | - if (bbox.Intersects(fdr.Geometry.EnvelopeInternal)) | ||
| 137 | - list.Add(fdr.Geometry); | ||
| 160 | + var geom = feature.Geometry; | ||
| 161 | + var testBox = geom != null ? geom.EnvelopeInternal : new Envelope(bbox); | ||
| 162 | + if (bbox.Intersects(testBox)) | ||
| 163 | + yield return new KeyValuePair<uint, FeatureDataRow>(id, feature); | ||
| 164 | + id++; | ||
| 138 | 165 | } | |
| 139 | - return list; | ||
| 166 | + else | ||
| 167 | + foreach (FeatureDataRow feature in _features.Rows) | ||
| 168 | + { | ||
| 169 | + var geom = feature.Geometry; | ||
| 170 | + var testBox = geom != null ? geom.EnvelopeInternal : new Envelope(bbox); | ||
| 171 | + if (bbox.Intersects(testBox) && FilterDelegate(feature)) | ||
| 172 | + yield return new KeyValuePair<uint, FeatureDataRow>(id, feature); | ||
| 173 | + id++; | ||
| 174 | + } | ||
| 175 | + } | ||
| 140 | 176 | } | |
| 141 | 177 | ||
| 142 | 178 | /// <summary> | |
@@ -147,17 +183,10 @@ public Collection<IGeometry> GetGeometriesInView(Envelope bbox) | |||
| 147 | 183 | public Collection<uint> GetObjectIDsInView(Envelope bbox) | |
| 148 | 184 | { | |
| 149 | 185 | var list = new Collection<uint>(); | |
| 150 | - uint i = 0; | ||
| 151 | - foreach (FeatureDataRow fdr in _features.Rows) | ||
| 152 | - { | ||
| 153 | - i++; | ||
| 154 | - if (!fdr.Geometry.IsEmpty) | ||
| 155 | - if (FilterDelegate == null || FilterDelegate(fdr)) | ||
| 156 | - { | ||
| 157 | - if (bbox.Intersects(fdr.Geometry.EnvelopeInternal)) | ||
| 158 | - list.Add(i); | ||
| 159 | - } | ||
| 160 | - } | ||
| 186 | + | ||
| 187 | + foreach (var idFeature in EnumerateFeatures(bbox)) | ||
| 188 | + list.Add(idFeature.Key); | ||
| 189 | + | ||
| 161 | 190 | return list; | |
| 162 | 191 | } | |
| 163 | 192 | ||
@@ -168,7 +197,10 @@ public Collection<uint> GetObjectIDsInView(Envelope bbox) | |||
| 168 | 197 | /// <returns>geometry</returns> | |
| 169 | 198 | public IGeometry GetGeometryByID(uint oid) | |
| 170 | 199 | { | |
| 171 | - return ((FeatureDataRow)_features.Rows[(int)oid]).Geometry; | ||
| 200 | + lock (_featuresLock) | ||
| 201 | + { | ||
| 202 | + return ((FeatureDataRow)_features.Rows[(int)oid]).Geometry; | ||
| 203 | + } | ||
| 172 | 204 | } | |
| 173 | 205 | ||
| 174 | 206 | /// <summary> | |
@@ -178,18 +210,24 @@ public IGeometry GetGeometryByID(uint oid) | |||
| 178 | 210 | /// <param name="ds">FeatureDataSet to fill data into</param> | |
| 179 | 211 | public void ExecuteIntersectionQuery(IGeometry geom, FeatureDataSet ds) | |
| 180 | 212 | { | |
| 181 | - var fdt = new FeatureDataTable(); | ||
| 182 | - fdt = _features.Clone(); | ||
| 213 | + FeatureDataTable fdt; | ||
| 214 | + lock (_featuresLock) | ||
| 215 | + fdt = _features.Clone(); | ||
| 183 | 216 | ||
| 184 | - foreach (FeatureDataRow fdr in _features) | ||
| 185 | - if (FilterDelegate == null || FilterDelegate(fdr)) | ||
| 217 | + fdt.BeginLoadData(); | ||
| 218 | + var pg = new NetTopologySuite.Geometries.Prepared.PreparedGeometryFactory().Create(geom); | ||
| 219 | + foreach (var idFeature in EnumerateFeatures(geom.EnvelopeInternal)) | ||
| 220 | + { | ||
| 221 | + var fdr = idFeature.Value; | ||
| 222 | + if (pg.Intersects(fdr.Geometry)) | ||
| 186 | 223 | { | |
| 187 | - if (fdr.Geometry.EnvelopeInternal.Intersects(geom.EnvelopeInternal)) | ||
| 188 | - { | ||
| 189 | - fdt.LoadDataRow(fdr.ItemArray, false); | ||
| 190 | - ((FeatureDataRow)fdt.Rows[fdt.Rows.Count - 1]).Geometry = fdr.Geometry; | ||
| 191 | - } | ||
| 224 | + fdt.LoadDataRow(fdr.ItemArray, true); | ||
| 225 | + var tmpGeom = fdr.Geometry; | ||
| 226 | + if (tmpGeom != null) | ||
| 227 | + ((FeatureDataRow)fdt.Rows[fdt.Rows.Count - 1]).Geometry = (IGeometry)tmpGeom.Clone(); | ||
| 192 | 228 | } | |
| 229 | + } | ||
| 230 | + fdt.EndLoadData(); | ||
| 193 | 231 | ||
| 194 | 232 | ds.Tables.Add(fdt); | |
| 195 | 233 | } | |
@@ -201,21 +239,20 @@ public void ExecuteIntersectionQuery(IGeometry geom, FeatureDataSet ds) | |||
| 201 | 239 | /// <param name="ds">FeatureDataSet to fill data into</param> | |
| 202 | 240 | public void ExecuteIntersectionQuery(Envelope box, FeatureDataSet ds) | |
| 203 | 241 | { | |
| 204 | - var fdt = new FeatureDataTable(); | ||
| 205 | - fdt = _features.Clone(); | ||
| 242 | + FeatureDataTable fdt; | ||
| 243 | + lock (_featuresLock) | ||
| 244 | + fdt = _features.Clone(); | ||
| 206 | 245 | ||
| 207 | - foreach (FeatureDataRow fdr in _features) | ||
| 208 | - if (fdr.Geometry != null) | ||
| 209 | - { | ||
| 210 | - if (FilterDelegate == null || FilterDelegate(fdr)) | ||
| 211 | - { | ||
| 212 | - if (fdr.Geometry.EnvelopeInternal.Intersects(box)) | ||
| 213 | - { | ||
| 214 | - fdt.LoadDataRow(fdr.ItemArray, false); | ||
| 215 | - (fdt.Rows[fdt.Rows.Count - 1] as FeatureDataRow).Geometry = fdr.Geometry; | ||
| 216 | - } | ||
| 217 | - } | ||
| 218 | - } | ||
| 246 | + fdt.BeginLoadData(); | ||
| 247 | + foreach (var idFeature in EnumerateFeatures(box)) | ||
| 248 | + { | ||
| 249 | + var fdr = idFeature.Value; | ||
| 250 | + fdt.LoadDataRow(fdr.ItemArray, false); | ||
| 251 | + var geom = fdr.Geometry; | ||
| 252 | + if (geom != null) | ||
| 253 | + ((FeatureDataRow)fdt.Rows[fdt.Rows.Count - 1]).Geometry = (IGeometry)geom.Clone(); | ||
| 254 | + } | ||
| 255 | + fdt.EndLoadData(); | ||
| 219 | 256 | ||
| 220 | 257 | ds.Tables.Add(fdt); | |
| 221 | 258 | } | |
@@ -226,18 +263,24 @@ public void ExecuteIntersectionQuery(Envelope box, FeatureDataSet ds) | |||
| 226 | 263 | /// <returns>number of features</returns> | |
| 227 | 264 | public int GetFeatureCount() | |
| 228 | 265 | { | |
| 229 | - return _features.Rows.Count; | ||
| 266 | + lock(_featuresLock) | ||
| 267 | + return _features.Rows.Count; | ||
| 230 | 268 | } | |
| 231 | 269 | ||
| 232 | 270 | /// <summary> | |
| 233 | - /// Throws an NotSupportedException. Attribute data is not supported by this datasource | ||
| 271 | + /// Gets a specific feature from the data source by its <paramref name="rowId"/> | ||
| 234 | 272 | /// </summary> | |
| 235 | - /// <param name="rowId"></param> | ||
| 236 | - /// <returns></returns> | ||
| 273 | + /// <param name="rowId">The id of the row</param> | ||
| 274 | + /// <returns>A feature data row</returns> | ||
| 237 | 275 | public FeatureDataRow GetFeature(uint rowId) | |
| 238 | 276 | { | |
| 239 | - if (FilterDelegate == null || FilterDelegate(_features[(int) rowId])) | ||
| 240 | - return _features[(int) rowId]; | ||
| 277 | + lock (_featuresLock) | ||
| 278 | + { | ||
| 279 | + if (rowId > _features.Rows.Count) | ||
| 280 | + return null; | ||
| 281 | + if (FilterDelegate != null && FilterDelegate(_features[(int) rowId])) | ||
| 282 | + return _features[(int) rowId]; | ||
| 283 | + } | ||
| 241 | 284 | ||
| 242 | 285 | return null; | |
| 243 | 286 | } | |
@@ -248,15 +291,19 @@ public FeatureDataRow GetFeature(uint rowId) | |||
| 248 | 291 | /// <returns>boundingbox</returns> | |
| 249 | 292 | public Envelope GetExtents() | |
| 250 | 293 | { | |
| 251 | - if (_features.Rows.Count == 0) | ||
| 252 | - return null; | ||
| 253 | - var box = new Envelope(); | ||
| 254 | - | ||
| 255 | - foreach (FeatureDataRow fdr in _features.Rows) | ||
| 256 | - if (fdr.Geometry != null && !fdr.Geometry.IsEmpty) | ||
| 257 | - box.ExpandToInclude(fdr.Geometry.EnvelopeInternal); | ||
| 294 | + lock (_featuresLock) | ||
| 295 | + { | ||
| 296 | + if (_features.Rows.Count == 0) | ||
| 297 | + return null; | ||
| 298 | + var box = new Envelope(); | ||
| 258 | 299 | ||
| 259 | - return box; | ||
| 300 | + foreach (FeatureDataRow fdr in _features.Rows) | ||
| 301 | + { | ||
| 302 | + if (fdr.Geometry != null && !fdr.Geometry.IsEmpty) | ||
| 303 | + box.ExpandToInclude(fdr.Geometry.EnvelopeInternal); | ||
| 304 | + } | ||
| 305 | + return box; | ||
| 306 | + } | ||
| 260 | 307 | } | |
| 261 | 308 | ||
| 262 | 309 | /// <summary> | |
@@ -300,8 +347,8 @@ public bool IsOpen | |||
| 300 | 347 | /// </summary> | |
| 301 | 348 | public int SRID | |
| 302 | 349 | { | |
| 303 | - get { return _SRID; } | ||
| 304 | - set { _SRID = value; } | ||
| 350 | + get { return _srid; } | ||
| 351 | + set { _srid = value; } | ||
| 305 | 352 | } | |
| 306 | 353 | ||
| 307 | 354 | /// <summary> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -247,17 +247,17 @@ public override void Render(Graphics graphics, Map map) | |||
| 247 | 247 | private void GetTileOnThread(object parameter) | |
| 248 | 248 | { | |
| 249 | 249 | object[] parameters = (object[])parameter; | |
| 250 | - if (parameters.Length != 4) throw new ArgumentException("Three parameters expected"); | ||
| 250 | + if (parameters.Length != 5) throw new ArgumentException("Five parameters expected"); | ||
| 251 | 251 | ITileProvider tileProvider = (ITileProvider)parameters[0]; | |
| 252 | 252 | TileInfo tileInfo = (TileInfo)parameters[1]; | |
| 253 | 253 | MemoryCache<Bitmap> bitmaps = (MemoryCache<Bitmap>)parameters[2]; | |
| 254 | 254 | AutoResetEvent autoResetEvent = (AutoResetEvent)parameters[3]; | |
| 255 | - | ||
| 255 | + bool retry = (bool) parameters[4]; | ||
| 256 | 256 | ||
| 257 | - byte[] bytes; | ||
| 257 | + var setEvent = true; | ||
| 258 | 258 | try | |
| 259 | 259 | { | |
| 260 | - bytes = tileProvider.GetTile(tileInfo); | ||
| 260 | + byte[] bytes = tileProvider.GetTile(tileInfo); | ||
| 261 | 261 | Bitmap bitmap = new Bitmap(new MemoryStream(bytes)); | |
| 262 | 262 | bitmaps.Add(tileInfo.Index, bitmap); | |
| 263 | 263 | if (_fileCache != null) | |
@@ -267,6 +267,12 @@ private void GetTileOnThread(object parameter) | |||
| 267 | 267 | } | |
| 268 | 268 | catch (WebException ex) | |
| 269 | 269 | { | |
| 270 | + if (retry) | ||
| 271 | + { | ||
| 272 | + GetTileOnThread(new object[] { tileProvider, tileInfo, bitmaps, autoResetEvent, false }); | ||
| 273 | + setEvent = false; | ||
| 274 | + return; | ||
| 275 | + } | ||
| 270 | 276 | if (_showErrorInTile) | |
| 271 | 277 | { | |
| 272 | 278 | //an issue with this method is that one an error tile is in the memory cache it will stay even | |
@@ -287,7 +293,7 @@ private void GetTileOnThread(object parameter) | |||
| 287 | 293 | } | |
| 288 | 294 | finally | |
| 289 | 295 | { | |
| 290 | - autoResetEvent.Set(); | ||
| 296 | + if (setEvent) autoResetEvent.Set(); | ||
| 291 | 297 | } | |
| 292 | 298 | } | |
| 293 | 299 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -221,7 +221,9 @@ | |||
| 221 | 221 | <Compile Include="Utilities\LeastSquaresTransform.cs" /> | |
| 222 | 222 | <Compile Include="Utilities\LineOffset.cs" /> | |
| 223 | 223 | <Compile Include="Utilities\Providers.cs" /> | |
| 224 | + <Compile Include="Utilities\Surrogates.Helper.cs" /> | ||
| 224 | 225 | <Compile Include="Utilities\Surrogates.cs" /> | |
| 226 | + <Compile Include="Utilities\Surrogates.Brushes.cs" /> | ||
| 225 | 227 | <Compile Include="Utilities\Transform.cs" /> | |
| 226 | 228 | <Compile Include="Utilities\Version.cs" /> | |
| 227 | 229 | <Compile Include="Utilities\Wfs\FeatureTypeInfo.cs" /> | |
@@ -231,6 +233,7 @@ | |||
| 231 | 233 | <Compile Include="Utilities\Wfs\IXPathQueryManager.cs" /> | |
| 232 | 234 | <Compile Include="Utilities\Wfs\OGCFilter_FE1_1_0.cs" /> | |
| 233 | 235 | <Compile Include="Utilities\Wfs\PathNode.cs" /> | |
| 236 | + <Compile Include="Utilities\ReflectionUtility.cs" /> | ||
| 234 | 237 | <Compile Include="Utilities\Wfs\WFS1_0_0_XPathTextResources.cs" /> | |
| 235 | 238 | <Compile Include="Utilities\Wfs\WFS1_1_0_XPathTextResources.cs" /> | |
| 236 | 239 | <Compile Include="Utilities\Wfs\WFS_1_0_0_TextResources.cs" /> | |
| Back | FazBrowse Home | New Git URL |
0 commit comments