Split polygon on a layer using polyline

Hi,

I am able to edit and clip polygon in an OGR Layer using cmSplitByPolyline. Layer saves fine as a shapefile to computer but upon saving ogr layer 1 half of the polygon is updated to the server only and other half is lost somehow.
Need guidance

This is probably because you read 1 feature and create 2 features. So one of the two features needs to be added. The OGR Layer has some glitches likes this. When time permits we try to improve it.

Are you using MW5 and the shapefile editor or are you using MapWinGIS (the mapping component) in your own application? If the latter could you share the relevant code?

I’ll create a JIRA issue for it.

I am using Mapwingis active x control in a c# based windows app. Sure, Please find the code below:

OgrLayer layer = new OgrLayer();
layer.OpenFromDatabase(CONNECTION_STRING, layerName, true);
sqlOGRUpdateHandle = axMap1.AddLayer(layer, true);
_shpfile = layer.GetBuffer();
_shpfile.InteractiveEditing = true;

private void ToolStripSplitByLine_Click(object sender, EventArgs e)
{
    _shpfile.StartEditingShapes(true, null);
    axMap1.CursorMode = tkCursorMode.cmSplitByPolyline;
}

private void AxMap1_ChooseLayer(object sender, AxMapWinGIS._DMapEvents_ChooseLayerEvent e)
{
    if (axMap1.CursorMode == tkCursorMode.cmSplitByPolyline)
    {
        e.layerHandle = sqlOGRUpdateHandle;
    }
}

private void ToolStripStopAndSaveEditings_Click(object sender, EventArgs e)
{
    int count;
    var saveResults = layer.SaveChanges(out count);
    layer.Close();
    axMap1.CursorMode = tkCursorMode.cmPan;
    MessageBox.Show("Changes Saved Successfully");
    axMap1.Refresh();
}

I don’t see anything obviously wrong.

We need to have a closer look and do some debugging.

I created MWGIS-203 for this.

Hmm alright, I will be waiting :slight_smile:

Thank you!

Hey Mumair,

What database you are using (SQLServer, Postgis, …) ?
Also can you tell us which version of mapwingis you’re using.

Hi,

I am using MS SQL Server for storing the spatial data
and using version 5.0.0.0 of AxMapWinGIS

Thank you

Hey Mumair,

Can you verify there are no errors on the db-side when executing the code you posted by:

  • running a sql trace (using SQLProfiler, good post about it here)
  • putting a breakpoint just after the SaveChanges call and checking LastError on the layer object

Hi,
trace.zip (27.4 KB)
LastErrorCode returns me 0, tried multiple times.
Trace file is attached as well as it’s xml.
Looks like nothing odd there but your expert opinion would be required obviously :slight_smile:

Hi all, I’m trying to do the same thing with MapWindow5 and gave me the same result.
Splitting with polyline on MapWindow 5:

Splitted

Result on SQL Server

Hye Mumair,

thanks for the quick feedback - your trace is not setup correctly:

  • stop the trace if still running
  • go to the File menu, select Properties
  • in the ‘Events Selection’ tab, tick the ‘Show all events’ box (below the list of events on the right side of the tab)
  • make sure you tick the ‘Exception’ event under the ‘Errors and Warnings’ category (

My bad,
here you go.
trace.zip (17.3 KB)

But after multiple tries this time I got 303 error on lasterrorcode as well[trace.zip|attachment]

Ok thanks this helps a lot - the trace tells me two things:
a) it’s not on the database (yay a bug :p)
b) the database never gets an insert from mapwingis so something goes wrong doing the update/inserts

As suggested @Mathijs.Dumon, running a SQL trace gave me error n 2601: "Cannot insert a duplicate key row in object ‘‘sys.syssingleobjrefs’’ with unique index ‘clst’. Any idea to solve that?

According to the MSDN:
sys.syssingleobjrefs Exists in every database. Contains a row for each general N-to-1 reference.

are you sure this was related to your query? When running a SQLProfiler you’ll see a lot of queries unrelated to what you are doing (unless you’re the only person on that db).

It’s the only exception in Profiler with 25623. Every 42 attempts with 2601 exception, gave me one 25623

.

It’s a local server only created for this purpose.

Yay! I got you work to do :smiley:
This is actually very strange! leaves the previous one out and saves the new one completely