MapWindow Developer Team : MapWindow Discussion Forum
Hi, I added function for reading data layers through OGR. I added temporary procedure to CUtils class for testing: STDMETHODIMP CUtils::ConvertLayer(BSTR ShapefileName, ShpfileType shpType, ICallback *cBack, IShapefile** sf) I tested it with MapInfo *.ta
[New functionality] Reading and writing data layers though OGR
Posted by: Sergei ()
Date: August 27, 2009 02:05PM

Hi,

I added function for reading data layers through OGR. I added temporary procedure to CUtils class for testing:

STDMETHODIMP CUtils::ConvertLayer(BSTR ShapefileName, ShpfileType shpType, ICallback *cBack, IShapefile** sf)

I tested it with MapInfo *.tab format. Now it’s useful only for conversion of different file formats to the shapefile. But it’s possible to get more:
– to write backward procedure for saving shapefiles in different formats;
– to have in-memory shapefiles based on file formats other then shapefile. In principle with the editing capability (not for all formats though). To implement it we need pure in-memory mode for CShapefile which doesn’t address disk version.

Complete list of supported layer formats is here [www.gdal.org].

Write your thoughts about this functionality, please.

Regards,
Sergei

Options: ReplyQuote
Re: [New functionality] Reading and writing data layers though OGR
Posted by: pmeems ()
Date: August 31, 2009 04:04AM

Sergei,

I'll try and make some test scripts using your new functionality. You've added a lot of new features recently so I hope I can keep up ;)

Thanks,

Paul

--
Don't forget to read the new documentation: www.mapwindow.org/documentation/mapwingis4.8
Join us Google+: MapWindow GIS Google+ Community
Join the MapWindow Group on LinkedIn! LinkedIn - MapWindow Group

Download the latest beta installer at:
tinyurl.com/mwMonthly 32-Bit
tinyurl.com/mwMonthlyx64 64-Bit
Follow me on Twitter MapWindow_nl to read when a new installer is published.

---
Paul Meems
The Netherlands
[www.bontepaarden.nl]
Release manager, configuration manager and
forum moderator of MapWindow GIS

Owner of MapWindow.nl - Support for
Dutch speaking users: www.mapwindow.nl

*******
Everything I say or write is my personal opinion and
not the opinion of the company I work for.
*******
View my profile on LinkedIn

Options: ReplyQuote
Re: [New functionality] Reading and writing data layers though OGR
Posted by: pmeems ()
Date: September 07, 2009 03:21AM

Sergei,

I'm having trouble understanding this new function.
I'm trying to create a testscript to convert a MapInfo file in to a shapefile:
MapWinGIS.Utils utils = new Utils();
MapWinGIS.Shapefile sf = new Shapefile();
sf = utils.ConvertLayer(@"E:\SampleData\MapInfo\Admin_Units.MIF", ShpfileType.SHP_POLYGON, null);
sf.SaveAs(sDir + "\\Mapinfo.shp", null);
But I don't understand how to use it. You're description says the parameters are about shapefiles and it outputs a shapefile.

Could you please post your (VB6) code about the tab-format and could you upload the used tab file to the SampleData folder in SVN?

Thanks,

Paul

--
Don't forget to read the new documentation: www.mapwindow.org/documentation/mapwingis4.8
Join us Google+: MapWindow GIS Google+ Community
Join the MapWindow Group on LinkedIn! LinkedIn - MapWindow Group

Download the latest beta installer at:
tinyurl.com/mwMonthly 32-Bit
tinyurl.com/mwMonthlyx64 64-Bit
Follow me on Twitter MapWindow_nl to read when a new installer is published.

---
Paul Meems
The Netherlands
[www.bontepaarden.nl]
Release manager, configuration manager and
forum moderator of MapWindow GIS

Owner of MapWindow.nl - Support for
Dutch speaking users: www.mapwindow.nl

*******
Everything I say or write is my personal opinion and
not the opinion of the company I work for.
*******
View my profile on LinkedIn



Edited 1 time(s). Last edit at 09/07/2009 03:22AM by pmeems.

Options: ReplyQuote
Re: [New functionality] Reading and writing data layers though OGR
Posted by: geofran80 ()
Date: September 07, 2009 04:19AM

Friends, in this case and much others, would be useful for beginner developers of MapWindow to put some sample code for the news of MapWinGIS OCX related with MapWinGeoproc, Utils, and so much.

Some of these aren't documented and we haven't sample code to use in our projects.

Thanks.

Francisco J.

Options: ReplyQuote
Re: [New functionality] Reading and writing data layers though OGR
Posted by: Sergei ()
Date: September 07, 2009 01:34PM

Hi, Paul, Francisco

This function was meant for testing purposes. Probably it'll be changed later. I used the following vb6 sub for testing (my own fucntions here, but it's understandable I suppose). I've tested tab file just now and it works. I'll didn't tested it for mif as long as I remember. Paul, probably you'll try it. Write on any problems.

Francisco, I'll do it for my functions. But it's rather unlikely, that I'll have time before the end of the year. I'll readily answer questions though ;)

Regards,
Sergei

Public Sub ReadThroughOGR()

  Dim sFileName As String
  Dim sfNew As MapWinGIS.ShapeFile
  Dim aList() As String
  Dim iChoice As Long
  Dim shpType As MapWinGIS.ShpfileType
    
    sFileName = MMain.OpenFile(enShapefile, False)
    If Not fso.FileExists(sFileName) Then Exit Sub
      
    ' for formats with geometries of various types in one file
    If LCase$(MMain.FileName(sFileName, enFnExt)) = "tab" Then
      ReDim aList(1 To 3)
      aList(1) = "Point"
      aList(2) = "Polyline"
      aList(3) = "Polygon"
        
      iChoice = FAppOptions.Init(aList, "Choose object type for saving", "Choose file type")
      If iChoice = -1 Then Exit Sub
      
      Select Case iChoice
        Case 1: shpType = SHP_POINT
        Case 2: shpType = SHP_POLYLINE
        Case 3: shpType = SHP_POLYGON
      End Select
    Else
      ' for formats with geometries of single type in one file
      shpType = SHP_NULLSHAPE
    End If
    
    Set sfNew = Utils.ConvertLayer(sFileName, shpType, Nothing)
    If sfNew Is Nothing Then
      MsgBox "Null was returned", vbInformation
      Exit Sub
    End If
    
    sFileName = MMain.SaveFile(enShapefile)
    If Len(sFileName) = 0 Then Exit Sub
    If sfNew.SaveAs(sFileName) Then MsgBox "File was saved", vbInformation
End Sub

Options: ReplyQuote
Re: [New functionality] Reading and writing data layers though OGR
Posted by: pmeems ()
Date: September 08, 2009 05:12AM

Thanks Sergei your VB6 code did help.

I now understand you need to tell the converter in what type the created shapefile needs to be.

I've created a test script: [svn.mapwindow.org]
This script is converting MIF files ok. I couldn't test a TAB file because I don't have such a file. Could you provide yours?
I also tested with a dgn file and some csv files, but those files failed to convert.

In your VB6 example you use SHP_NULLSHAPE as well. When should that be used?

I want to suggest to rename the first argument from ShapefileName to filename because shapefile names aren't passed.

Thanks,

Paul

--
Don't forget to read the new documentation: www.mapwindow.org/documentation/mapwingis4.8
Join us Google+: MapWindow GIS Google+ Community
Join the MapWindow Group on LinkedIn! LinkedIn - MapWindow Group

Download the latest beta installer at:
tinyurl.com/mwMonthly 32-Bit
tinyurl.com/mwMonthlyx64 64-Bit
Follow me on Twitter MapWindow_nl to read when a new installer is published.

---
Paul Meems
The Netherlands
[www.bontepaarden.nl]
Release manager, configuration manager and
forum moderator of MapWindow GIS

Owner of MapWindow.nl - Support for
Dutch speaking users: www.mapwindow.nl

*******
Everything I say or write is my personal opinion and
not the opinion of the company I work for.
*******
View my profile on LinkedIn



Edited 1 time(s). Last edit at 09/08/2009 05:13AM by pmeems.

Options: ReplyQuote
Re: [New functionality] Reading and writing data layers though OGR
Posted by: Sergei ()
Date: September 08, 2009 12:45PM

Paul,

It's possible to pass shapefile through this convertion as well (don't know practical reason to do it apart from controlling correctness of conversion). SHP_NULLSHAPE should be used for shapefiles or any other formats which store geometries of only one type and the information about the type is present in the file itself.
As for problem with dgn, csv files sent me those, please, and I'll try to see what's wrong.

Renaming? Of course I'll do it. But I'll mention also that this function is for testing now. Probably some other parameters should be specified, so I don't recommend to use it in projects for now.

Regards,
Sergei

Options: ReplyQuote
Re: [New functionality] Reading and writing data layers though OGR
Posted by: pmeems ()
Date: September 08, 2009 02:31PM

The MapInfo file (MIF/MID) I used: SampleData/MapInfo/ This one is nicely converted to a polygon shapefile.
The MicroStation file (dgn) I used: SampleData/DGN/
The csv files: SampleData/CSV/

Hope it helps,

Paul

--
Don't forget to read the new documentation: www.mapwindow.org/documentation/mapwingis4.8
Join us Google+: MapWindow GIS Google+ Community
Join the MapWindow Group on LinkedIn! LinkedIn - MapWindow Group

Download the latest beta installer at:
tinyurl.com/mwMonthly 32-Bit
tinyurl.com/mwMonthlyx64 64-Bit
Follow me on Twitter MapWindow_nl to read when a new installer is published.

---
Paul Meems
The Netherlands
[www.bontepaarden.nl]
Release manager, configuration manager and
forum moderator of MapWindow GIS

Owner of MapWindow.nl - Support for
Dutch speaking users: www.mapwindow.nl

*******
Everything I say or write is my personal opinion and
not the opinion of the company I work for.
*******
View my profile on LinkedIn

Options: ReplyQuote
Re: [New functionality] Reading and writing data layers though OGR
Posted by: zjz0923 ()
Date: October 27, 2009 09:51AM

Hi Paul,

I have tested you script, use the same data file as you used. poly.DAT is converted to an empty shape file. it seems that the attribute header is correctly copied the dbf file, but the table is empty and the .shp is 0kb.

Could you adives me what might be the problem?

Thanks,

Yong WANG

Options: ReplyQuote
Re: [New functionality] Reading and writing data layers though OGR
Posted by: pmeems ()
Date: October 29, 2009 06:31AM

Yong,
The script had a minor glitch in naming the shapefile. I've fixed it and uploaded the modified script.
Could you download it again and try it once more.

You do have installed MapWindow v4.7 RC4?

Thanks,

Paul

--
Don't forget to read the new documentation: www.mapwindow.org/documentation/mapwingis4.8
Join us Google+: MapWindow GIS Google+ Community
Join the MapWindow Group on LinkedIn! LinkedIn - MapWindow Group

Download the latest beta installer at:
tinyurl.com/mwMonthly 32-Bit
tinyurl.com/mwMonthlyx64 64-Bit
Follow me on Twitter MapWindow_nl to read when a new installer is published.

---
Paul Meems
The Netherlands
[www.bontepaarden.nl]
Release manager, configuration manager and
forum moderator of MapWindow GIS

Owner of MapWindow.nl - Support for
Dutch speaking users: www.mapwindow.nl

*******
Everything I say or write is my personal opinion and
not the opinion of the company I work for.
*******
View my profile on LinkedIn

Options: ReplyQuote
Re: [New functionality] Reading and writing data layers though OGR
Posted by: zjz0923 ()
Date: October 29, 2009 08:40AM

Hi Paul,

Thanks for your reply.

I have change the shape file naming extensions.

But it still does not work for me.

I am MapWindow v4.7 RC4.

Shape files are created but, no features are converted.(the *.shp and *.shx are 0kb,, *.dbf has some feild headers, and nothing more)

Yong

Options: ReplyQuote
Re: [New functionality] Reading and writing data layers though OGR
Posted by: pmeems ()
Date: October 30, 2009 01:41AM

Yong,

That is very strange. Would you mind re-registring the ocx?
You can use regMapWinGIS.cmd or
regsvr32 /u /s MapWinGIS.ocx
regsvr32 MapWinGIS.ocx

If this isn't fixing it, would you get the latest binaries?
I compile them every Friday around noon (West-Europe time), that would be in 4-5 hours from now.
You can get it from LatestPatch.zip (13 MB)

Thanks,

Paul

--
Don't forget to read the new documentation: www.mapwindow.org/documentation/mapwingis4.8
Join us Google+: MapWindow GIS Google+ Community
Join the MapWindow Group on LinkedIn! LinkedIn - MapWindow Group

Download the latest beta installer at:
tinyurl.com/mwMonthly 32-Bit
tinyurl.com/mwMonthlyx64 64-Bit
Follow me on Twitter MapWindow_nl to read when a new installer is published.

---
Paul Meems
The Netherlands
[www.bontepaarden.nl]
Release manager, configuration manager and
forum moderator of MapWindow GIS

Owner of MapWindow.nl - Support for
Dutch speaking users: www.mapwindow.nl

*******
Everything I say or write is my personal opinion and
not the opinion of the company I work for.
*******
View my profile on LinkedIn

Options: ReplyQuote
Re: [New functionality] Reading and writing data layers though OGR
Posted by: zjz0923 ()
Date: November 02, 2009 09:02AM

It does not work for me still.

I gave up and try to look for alternatives

Options: ReplyQuote
Re: [New functionality] Reading and writing data layers though OGR
Posted by: pmeems ()
Date: November 03, 2009 12:17AM

I'm sorry to read you're giving up.
This should work, so please help me investigate this.

What Windows flavor are you using: XP, Vista, 32/64Bit?
What version of MapWindow are you using? RC4, w/o latest patch, 32/64Bit?
What happens if you use a different file to convert?

Thanks,

Paul

--
Don't forget to read the new documentation: www.mapwindow.org/documentation/mapwingis4.8
Join us Google+: MapWindow GIS Google+ Community
Join the MapWindow Group on LinkedIn! LinkedIn - MapWindow Group

Download the latest beta installer at:
tinyurl.com/mwMonthly 32-Bit
tinyurl.com/mwMonthlyx64 64-Bit
Follow me on Twitter MapWindow_nl to read when a new installer is published.

---
Paul Meems
The Netherlands
[www.bontepaarden.nl]
Release manager, configuration manager and
forum moderator of MapWindow GIS

Owner of MapWindow.nl - Support for
Dutch speaking users: www.mapwindow.nl

*******
Everything I say or write is my personal opinion and
not the opinion of the company I work for.
*******
View my profile on LinkedIn

Options: ReplyQuote
Re: [New functionality] Reading and writing data layers though OGR
Posted by: zjz0923 ()
Date: December 17, 2009 10:46AM

Hi Paul,

finaly, this function works for me.(I downloaded the latest version and it works now)
Thanks very much for your help!

Yong

Options: ReplyQuote


Sorry, only registered users may post in this forum.





Banner Exchange




GISCP.com




Send us your banner logo (160x120) for the space above, and add this MapWindow banner ad to your site:

Just paste this text in your page: