sharpmap / sharpmap Goto Github PK
View Code? Open in Web Editor NEWAn easy-to-use mapping library for use in web and desktop applications
License: GNU Lesser General Public License v2.1
An easy-to-use mapping library for use in web and desktop applications
License: GNU Lesser General Public License v2.1
Is there any plan to port library to new vertion of C# and support .NET Core?
I’m relatively new to GitHub and would like feedback on a couple of points before working on any updates and issuing pull request. Links are provided to relevant code.
Background:
I have been reviewing locks in above classes in relation to dynamic layers in VariableLayerCollection. I am managing dynamic layers and their geometries on a separate thread, and one or more of the dynamic layers may be used in more than one map (eg main map and overview, or map for mobile object X and another map for mobile object Y). Layers associated with single mobile object use GeometryProvider datasource, or multiple mobile objects may be shown in a single layer with GeometryFeatureProvider datasource using heading column to rotate symbol appropriately for each mobile object.
I note that locks are used in VectorLayer and GeometryFeatureProvider, but not in GeometryProvider. I think I understand the intent of the locks but I am unsure on the effectiveness of some of them as described below.
GeometryFeatureProvider
Underlying DataTable is safe for multi-threaded read operations, but not write.
Two locking objects (_featuresLock and _feautures ) are used but neither of these locks actually do anything to prevent modification to the rows in underlying FeatureDataTable. Would selective use of DataTable.Rows.SyncRoot be more effective?
GeometryProvider
Currently no locks at all. Locking on ICollection.SyncRoot would provide thread-safety, allowing updating of geometries and rendering to be appropriately synchronized (which is my main concern at the moment).
However, this raises another issue of potentially slowing rendering of entire map as all layers are processed sequentially. gennadiy_d_cp has proposed map.cs renders layers as parallel tasks see separate branch or perhaps modify to limit tasks to (predefined) groups of layers.
VectorLayer
Locks are used to restore datasource to open/closed state:
public override Envelope Envelope
protected void RenderInternal(Graphics g, MapViewport map, Envelope envelope, ITheme theme)
The same locking object is also used when open/closing datasource, but without restoring open/closed state:
protected void RenderInternal(Graphics g, MapViewport map, Envelope envelope, ITheme theme)
public void ExecuteIntersectionQuery(Envelope box, FeatureDataSet ds)
public void ExecuteIntersectionQuery(IGeometry geometry, FeatureDataSet ds)
Is there a reason for this, or should the latter be updated to restore open/closed state?
VariableLayerCollection
Public Static methods cause VariableLayerCollections to render simultaneously across all MapBox / MapImage instances. While this may be desirable in some cases, in other cases it makes sense for maps to be entirely independent as VariableLayerCollection may have different contents and different refresh rates may be appropriate for different maps.
Should both cases be supported? Or should public static members/methods be changed to instance level members/methods?
Similarly, am I correct in understanding the internal touchTest is used to temporarily delay raising redraw event if another user operation is in progress (eg pan)? I previously submitted a pull request to try and resolve some redraw issues here, but I think this should be cancelled as it is only a partial fix and doesn’t address above points.
Finally
Thanks to all involved in SharpMap. I continue to learn as I work through the code. I’m willing to contribute but still learning the finer arts on acceptable coding standards (eg use of inline comments etc). Any suggestions / constructive criticism will be well received.
Hi,
I am working on an snapping tool.I need to set mouse position on map,But it does not work.I use this code
private void snapToPoint(IPoint fdr) { if (fdr == null) return; var imagepoint = MapControl.Map.WorldToImage(fdr.Coordinate); snappingPoint = new System.Drawing.Point((int)Math.Round(imagepoint.X), (int)Math.Round(imagepoint.Y)); ; MapControl.BeginInvoke(new Action(() => { var u = MapControl.PointToClient(snappingPoint); snappingPoint.X += u.X; snappingPoint.Y += u.Y; Cursor.Position = u; }));}
I have also set
Cursor.Position = snappingPoint ;
but none of them works..What can I do ?
thanks
Hello:
I use SharpMap v1.1 to Render and Display a tif with SharpMap.Extensions.GdalRasterLayer .
When I open a RasterFile (.tif) with chinese-character fileName,it occur Exception with the file is not exit in the hardDisk
Exception Message:
/------------------------------------------------------------------------------------------------------
Couldn't load C:\Users\Administrator\Desktop\DataDemo\新建文件夹\798-505\白博文.tif
`C:\Users\Administrator\Desktop\DataDemo\鏂板缓鏂囦欢澶筡798-505\鐧藉崥鏂?tif' does not exist in the file system,
and is not recognised as a supported dataset name.
/---------------------------------------------------------------------------------------------------------
I serach for the answer and fount it come from gdalv1.9.2 gdal_csharp.dll, who case zhe exption with Encoding.Default ->Encoding.utf8, then make chinese-character bad.
So I rebuilt gdal1.9.2 and replace the gdal19.dll gdal_csharp.dll gdal_wrap.dll gdalconst_csharp.dll
gdalconst_wrap.dll ogr_csharp.dll ogr_wrap.dll osr_csharp.dll osr_wrap.dll in Sharp.Extension folder
In a project I use them but Invaid, It occur other Exception "SharpMap.Layers.GdalRasterLayer Init Exception"
LIKE this
How can I do ?
Dear Gurus!
I took BlueMarble 40.ecw file , loaded it in GlobalMapper, reprojected it to the EPSG 3857 (wgs84 Mercator) and saved with setting parameter "Set background pixels invisible". After that I see it in arcmap and do not see in sharpmap project. This is an example of .ecw file
Currently the SharpMap ISession
interface resides in the SharpMap.CoordinateSystems
namespace.
It is more reasonable to have it in the SharpMap
namespace.
https://github.com/SharpMap/SharpMap/blob/master/SharpMap/packages.config references .
Would you be open to a pull request updating to the most recent version?
Since this is potentially breaking, is this a major revision to your package 2.0.0.0 or only a minor revision? 1.2.0.0?
Hi,
I am using sharp map and on my pc with windows 10 every thing works fine. I have a sqlserver2008 provider which connects to a remote sql server and loads one layer and shows and every thing is OK,
But when I moved my app on windows 7 on two PCs my layer did not load and sharpmap only shows a big red rectangular with an X in it. What can make this happen?
I know my sql connection works fine on all of PCs and I can work with them and also the envelope of my layer is right but Is does not render any thing,
What I need to fix this problem?
When does Red rectangle appears?
thanks
Hello.
I'm openning one shape and something like to 100 dynamic objects (polygons and images).
This is very slow to render. Sometimes is taking 5 seconds to rendering when I change the zoom or moved the map.
Have a way to make it faster?
Hi,
I have created a map box and added some layers into that map, every thing worked fine until suddenly I faced an strange problem,The zoom using mouse wheel does not work all the map box area,It only works ob corners and the center of map zoom using wheel dont work..Waht possible problems may cause this problem?
Here is an image of the areas that zoom works and where it does not work
https://i.imgsafe.org/0606841f7b.png
thanks for your help
Hi, I'm using SharpMap.UI's Mapbox control. In my Form_Load, I load an MBTiles layer into the mapbox
MbTilesTileSource source = new MbTilesTileSource(sourcepath);
SharpMap.Layers.TileLayer layer = new SharpMap.Layers.TileLayer(source, "Map");
mapBox1.Map.BackgroundLayer.Add(layer);
mapBox1.Map.Zoom = 40000000;
mapBox1.Refresh();
The issue is that not all the tiles display, and there's a hole in the map. (I have attached a screenshot). If I call refresh at a later time (such as when the user clicks), the entire map displays without issue. When working with Brutile by itself (using their MBTiles example), I did not notice this issue.
Is there maybe an event I can hook into to know when the control is ready to render the whole viewport?
Hi,
I have tested and found that reprojection of shape files have some problems, I can perform reprojection on some data but some of them has problems and make layer invisible or even make a map to draw a big red rectangle on it.
Is there a secure way to perform a shape file re projection on layers?
There is a problem with using a halo on text labels.
The render routine creates a new Pen object based on the specified HaloBrush and Halo (width). However, it leaves the MiterLimit of this pen at the default of 10.0f.
The result is that letters with sharp turns, such as "M" or "W" create spikes in the halo effect.
The solution is to specify a small MiterLimit when the Pen is created (at line 204 in CharacterPointSymbolizer.cs).
Also the newly-created Pen is not disposed correctly. I would suggest therefore that the OnRenderInternal method be changed to:
internal override void OnRenderInternal(PointF pt, Graphics g)
{
if (Halo > 0)
{
//need to look it up
using (var path = new GraphicsPath(FillMode.Winding))
using (var haloPen = new Pen(HaloBrush, 2 * Halo) { MiterLimit = 1.0f })
{
path.AddString(_text, Font.FontFamily, (int)Font.Style, Font.Size, pt, StringFormat);
g.DrawPath(haloPen, path);
g.FillPath(Foreground, path);
}
}
else
{
g.DrawString(_text, Font, Foreground, pt, StringFormat);
}
}
I have a problem when rendering map with layers have different SRID.
For example, I initialize a map with SRID 25832 since I would like to use 25832 as a default SRID when changing something such as Center or Envelope. Also when getting drawing coordinates on map.
var map = new Map {
SRID = 25832
};
For background layer, I use OSM (SRID 3857)
// OSM SRID 3857
var osmLayer = new TileAsyncLayer(BruTile.Predefined.KnownTileSources.Create(), "OSM");
map.BackgroundLayer.Add(osmLayer);
And WMS layer that has SRID 25832
// SRID 25832
var wmsLayer = new WmsLayer("wmslayer", "...");
map.Layers.Add(wmsLayer);
The issue is background map doesn't render to correct location when I set new center for map since the background layer has a different SRID with map and WMS layer, I think
// coordinate in 25832
map.Center = new Coordinate(475666, 6350463);
map.Refresh();
Anyone know how I can make them work together. Thanks :)
I don`t find any sample to open ozi (*.map *.ozf2 *.ozf3) files. Maybe somebody work with it.
Hello,
I am unable to select the feature on the map and highlight the selected. geometry.
I have 2 layers Land, and its label. I wanted to make a tool to enable the click on map feature, highlight it with different background color and show the attribute on grid.
Edit:
I have tried following
private void mapBox_MouseUp(GeoAPI.Geometries.Coordinate worldPos, MouseEventArgs imagePos)
{
var p = mapBox.Map.ImageToWorld(imagePos.Location);
SharpMap.Data.FeatureDataSet ds = new SharpMap.Data.FeatureDataSet();
foreach (var layer in mapImage.Map.Layers)
{
var queryLayer = layer as SharpMap.Layers.ICanQueryLayer;
if (queryLayer != null)
queryLayer.ExecuteIntersectionQuery(parcelVectorLayer.Envelope, ds);
}
if (ds.Tables.Count > 0) dataGridView1.DataSource = ds.Tables[0];
}
Hi,
I want t keep current map view extent and then use it when a new Map object loads into mapbox,
Any way How Can I get current map viewing envelope?
thanks
If zooming using the Shift-key and dragging a rectangle, the zoom behaves incorrectly. I've found that the method MapBox.GetImagesAsyncEnd zeroes out the variable _dragEndPoint. This will make the zoom calculations in OnMouseUp to produce the wrong result. When removing the code which change _dragEndPoint the zoom works as expected. I've tried to check everywhere the variable is used (only in OnMouseDown, OnMouseMove and OnMouseUp) and it seems like it would be safe to remove the line in GetImagesAsyncEnd, but I might be missing something.
The error can be reproduced in the WPFSamples application.
Hi
Team,
I am using your HeatLayer Map , but i have following issues with this :-
1.How can i change the size of Heatpoint.?
2.can i create a polygon of different color using heat map?
3.How can i style the HeatLayer?
4 What is BlendOperation how can i implement this.?
Moto To Achieve:- I have different values on different point for one Source and i have multiple source in my file i just want to show those all different sources to map using heat layer . Can i achieve this by creating Polygon or by creating Points . Please help .
I have already gone through your example but i cant achieve this by your example .
Regards,
Sgoyal.
Dear Gurus!
There was no problem with rendering labelLayers for polygon or point layers. But for line layer rendering is very long. There are about 300 rows for roads (line layer) with there labels (the picture attached) , and time for rendering is about 120 seconds.
The code is:
` private void setLabelLineLayer()
{
labelLayer = new LabelLayer(v_layer.LayerName.Trim() + "Label");
labelLayer.Enabled = v_layer.Enabled;
labelLayer.LabelColumn = m_layer.labelFieldName;
labelLayer.DataSource = v_layer.DataSource;
labelLayer.Theme = CreateTheme();
}
private static ITheme CreateTheme()
{
return new CustomTheme(StyleBasedOnAlignment);
}
private static IStyle StyleBasedOnAlignment(SharpMap.Data.FeatureDataRow dr)
{
var style = new LabelStyle
{
HorizontalAlignment = LabelStyle.HorizontalAlignmentEnum.Center,
VerticalAlignment = LabelStyle.VerticalAlignmentEnum.Middle,
Rotation = -20,
BackColor = Brushes.Pink,
Halo = new Pen(Brushes.LightBlue, 2)
};
return style;
}
`
What I can do to reduce rendering time?
Currently SharpMap relies on Common.Logging v2.0. This is stuck on Net20 Framework.
Current release of GeoAPI has a modified ICoordinateSystemServices. This enables us to remove conditional compilation of reprojection code
Hi,
While I want to open an shapefile It gives me this error
Must declare a coordinate system services object
what does this error mean?how can I fixe it?
This requires to add BruTile.Serialization to be added to SharpMap, as this is not part of BruTile.Desktop package anymore.
I have had the problem on and off for a while. If I create a brand new blank project and add SharpMap and SharpMap.UI from Nuget along with all the other stuff it drags in, I get an error when I try to put a MapBox on the form. It shows generally as something about SharpMap.UI already exists in the project. Well, sure it does since it was just added by NuGet.
On an existing project, MapBox simply stopped functioning. I had not updated the NuGet, it just stopped working and I can see it in the windows code, the MapBox is not visible in the designer window. I tried to delete, but then I can not add a new one because I get the same error as above.
Obviously, there is a problem with MapBox and VS 2015.
Any ideas?
We need to use more recent versions of NetTopologySuite, at least 1.13.4 or 1.14.
SharpMap.Map
is a pretty heavy class to pass around for rendering purposes.
Additionally a part of its properties is being computed upon access in performance critical sections of the rendering pipeline.
In order to faciliate and speed-up rendering I propose to extract the relevant portions of SharpMap.Map
into a new SharpMap.MapViewport
class. Please see attached file.
In order to benefit from this, the SharpMap.Layers.ILayer.Render
interface has to change, too:
/// <summary>
/// Renders the layer
/// </summary>
/// <param name="g">Graphics object reference</param>
/// <param name="map">Map which is rendered</param>
[Obsolete("Use Render(Graphics, MapViewport)")]
void Render(Graphics g, Map map);
/// <summary>
/// Renders the layer using the current viewport
/// </summary>
/// <param name="g">Graphics object reference</param>
/// <param name="map">Map which is rendered</param>
void Render(Graphics g, MapViewport map);
Hello,
In the source of
https://github.com/SharpMap/SharpMap/blob/Branches/1.0/SharpMap/Data/Providers/ShapeFile.cs
I think that there is a performance bottleneck in the methods IGeometry GetGeometryByID(uint oid) line 721 and FeatureDataRow GetFeature(uint rowId, FeatureDataTable dt) line 1367
In the case where _useMemoryCache is set to True, then there is no need to call OpenDbfStream which is very penalizing every time it's called.
So I think that the method GetGeometryByID(uint oid) could be refactored to take benefit of the memory cache by checking first of that flag is set to True before trying to read the file with OpenDbfStream
This issue is present in the code of the SharpMap DLLs published on nuget.org and on the files in this GitHub repository.
Hi,
In the dll version that I have downloaded this class does not excists..Do this works currently?where I can download last version of sharp map?It seems this version is not included in github..right?
I've been able to reduce number of errors on http://travis-ci.org/SharpMap/SharpMap down to 1.
Anyone has an idea of how to fix the last one?
It has to do with the "Version" task in SharpMap.targets.
The build system cannot find Microsoft.Build.Utilities.v3.5
. As a fallback I've created a task that get's along without needing this library, but the error condition is not cleared.
What is a proper way to calculate a phisical length of the line or area of the polygon (in Mercator projection , for example)?
Is there any tools in the SharpMap?
Hi,
In old versions of sqlserver2008 I could add a function as table name. but in the version here I can not, I only can add table names...I want to figure out what is chenged in new versions and how I can manege to use functions as table neme?
can some one helps me?
thank you
We need to refactor the IAsyncLayer to use one SharpMap core components so we can remove the dependancy on BruTile.
Hi,
I have faced a problem.When I want to style a vector feature set base on its data column if they have null values in that column nothing shows. I think there must be some rules to deal with null values. Is there any way to fix it?
thanks
I am using a mapBox control in which i load
a layer (GoogleTileSource) and one from Wms service (WmsLayer).
Whilst the first one works I cannot visualize the wms layer on the background layer.
I tried whit various WMS services.
this is the code i use:
// GoogleTileSource
TileLayer googleLayer = new TileAsyncLayer(new GoogleTileSource(new GoogleRequest(GoogleMapType.GoogleMap), new MemoryCache<byte[]>(100, 1000)), "TileLayer - Google");
mapBox1.Map.BackgroundLayer.Add(googleLayer);
// Wms layer
WmsLayer layer = new WmsLayer("catastale", "http://.....");
...
mapBox1.Map.Layers.Add(layer);
Thanks!
Hi,
I can easily set lable for polygons but when I use this code for lines or point it shows nothing. what can cause this problem?
here is my code
public static LabelLayer CreateLabelLayer(VectorLayer originalLayer, string labelColumnName) {
SharpMap.Layers.LabelLayer ll =
new SharpMap.Layers.LabelLayer(originalLayer.LayerName + ":Labels");
ll.DataSource = originalLayer.DataSource;
ll.LabelColumn = labelColumnName;
ll.Style.CollisionDetection = true;
ll.Style.CollisionBuffer = new SizeF(10F, 10F);
ll.LabelFilter =
SharpMap.Rendering.LabelCollisionDetection.ThoroughCollisionDetection;
ll.Style.Offset = new PointF(0, -10F);
ll.MultipartGeometryBehaviour =
SharpMap.Layers.LabelLayer.MultipartGeometryBehaviourEnum.CommonCenter;
ll.Style.Font = new Font(FontFamily.GenericSansSerif, 14);
ll.MaxVisible = originalLayer.MaxVisible;
ll.MinVisible = originalLayer.MinVisible;
ll.Style.Halo = new Pen(Color.White, 2);
ll.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
ll.CoordinateTransformation = originalLayer.CoordinateTransformation;
return labelLayer;
}
Hi,
Is there any way to limit maps zoom to extend of spacial vector layer?
thanks
Hi,
I am developing a tool to draw line and other shapes on map. I have found out that I have to fire DoPaint on tool after a mouse click.so.How can I fire it?
this method accespts PaintEventArgs and I dont know how to create this eventArg
Can some one please help me about it?
thanks
From https://developers.google.com/kml/documentation/kmlreference#stylemap:
<StyleMap id="ID">
<Pair id="ID">
<key>normal</key>
<styleUrl>...</styleUrl> or <Style>...</Style>
</Pair>
</StyleMap>
as you can see the Pair element supports both the styleUrl and Style child elements but currently only the styleUrl is supported.
With the introduction of GeoAPI.ICoordinateSystemServices
interface the need for the DotSpatalProjections
compiler directive has vanished.
We need to reflect that in the code.
Hello,
I am rendering simple map data with different parcel, load, construction etc. The data has label associated with data set. Database is in PostgreSQL/PostGIS.
I used following to load Label
SharpMap.Layers.VectorLayer roadVectorLayer = ...
SharpMap.Layers.LabelLayer parcelLabelLayer = MapHelper.GetLabelLayer("LabelLayer", "parcelno");
parcelLabelLayer.DataSource = roadVectorLayer.DataSource;
parcelLabelLayer.SRID = roadVectorLayer.SRID;
// some styles
mapBox.Map.Layers.Add(roadVectorLayer);
mapBox.Map.Layers.Add(parcelLabelLayer);
ParcelNo 9 is not placed properly.
How can I fix this kind of issue?
Hi,
I want to draw and edit geometries vertex by vertex..How can I do it?Can some one give me some examples?
I have already found this
https://github.com/SharpMap/_SharpMap/blob/master/Branches/0.9.5-DeltaShell/src/Common/NetTopologySuite/Geometries/Utilities/GeometryEditor.cs
but does not appear to works..or at least I dont know how to make it work
thanks
Using IAsyncLayer
as background layers exposes problems when continuously panning the map.
Arriving tiles are drawn at the wrong position.
Discussion on Codeplex
Currently the table schema defined in constructor argument or set via property is not evaluated correctly.
I have a simple question about loading speed.
Does sqlserver provider loads whole map or it only loads features in view port ?
I mean is there any way to increase loading and showing features into map speed when we have a large number of features?
Sorry, I couldn't find this in the documentation. I want to load a map from local files (jpg, for instance) in a folder structure. It looks like the expectation is that folder 0 will have 0.jpg, folder 1 will have two subfolders, 0 and 1, with each having files 0.jpg and 1.jpg in them, etc. So I have that structure, and I try to show them using a MapBox component from SharpMap.UI:
private void Form1_Load(object sender, EventArgs e)
{
string appdir = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
FileCache fc = new FileCache(appdir + "\\Tiles", "jpg");
SharpMap.Map map = mapBox1.Map;
FileTileProvider FTP = new FileTileProvider(fc);
TileSchema TS = new TileSchema();
Resolution R = new Resolution();
R.Id = "1";
TS.Resolutions.Add(R);
TileSource tileSource = new TileSource(FTP, TS);
map.Layers.Add(new TileLayer(tileSource, "1"));
mapBox1.Refresh();
}
I'm reasonably sure that the FileCache and FileTileProviders are working correctly, because if, for instance, I insert
byte[] foo = fc.Find(new TileIndex(0, 0, 1)); //works
the variable foo holds 16304 bytes (the size of my 1\0\0.jpg file). Likewise, if I insert
TileInfo TI = new TileInfo();
TI.Index = new TileIndex(0, 0, 1);
byte[] foo = FTP.GetTile(TI); //works
foo once again holds 16304 bytes. However, in debug if I look at the mapBox1.Map object, inspection says that in Layer 0 _bitmaps has zero elements, and nothing displays in the MapBox.
Kinda tearing my hair out here. Could someone point me in the right direction? I'm using the latest SharpMap and SharpMap.UI from NuGet in VS 2015.
Hi, I am new to SharpMap. I am trying to add a marker and making it move. It renders properly when i don't do any panning or zooming but the marker disappears whenever I zoom in or when I pans the map. The marker will reappear when i zoom out. It doesn't seems to be the MinVisible/MaxVisible settings as I have tried setting the MinVisible to 0 and MaxVisible to a high value. Attached is my sample program.
MiniMap.zip
May I know how to fix this issue? Thanks
Dear, Gurus!
Is there any tool for finding the coordinates of a point at a given distance from the beginning of a line (for example, a road)? Any ideas?
Under some circumstances, I have reproduced this with a large .ecw file, the GetTransform class does not calculate the inverse transformation needed to render the layer.
This is because the delta resulting from the matrix is less than epsilon value fixed in code, that is 1e-12, see the method ComputeInverse() from the GeoTransform class.
I do not know why it has been choosen this value and not another one, for sure the problem goes away, and the raster is rendered, if we remove this threshold from that method.
We could also solve it by lowering the value of Epsilon.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.