[IronPython] Conflicting information with Ironpython and MapWindowGIS interop

Dino Viehland dinov at microsoft.com
Fri Jul 2 21:43:18 CEST 2010


Does:

System.Activator.CreateInstance(MapWinGIS.Shapefile)

Work when you're using the original shape file?  It could be that Shapefile
is actually a COM interface.  Currently we don't support calling COM interfaces
directly but I've heard recently that it's something that C# lets you do. If
that is the case I think the Activator.CreateInstance call would work around 
this.

I think we're going to add support for calling COM interface types directly
for the next major release though.

> -----Original Message-----
> From: users-bounces at lists.ironpython.com [mailto:users-
> bounces at lists.ironpython.com] On Behalf Of Bruce Bromberek
> Sent: Friday, July 02, 2010 5:11 AM
> To: Discussion of IronPython
> Subject: Re: [IronPython] Conflicting information with Ironpython and
> MapWindowGIS interop
> 
> Thanks Dino.  But now I get
> 
> 
> >>> shapefile1 = MapWinGIS.Shapefile()
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> TypeError: Cannot create instances of Shapefile because it is abstract
> 
> So then I poked around a bit and found ShapeFileClass, but then I get
> a different error.
> 
> >>> s=MapWinGIS.ShapefileClass()
> >>> tst = s.Open(a,None)
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> ValueError: Could not convert argument 0 for call to Open.
> 
> I guess its time to add IronPython in Action back to my Safari account
> and read the C# stuff I skipped over before.
> 
> 
> On Thu, Jul 1, 2010 at 9:34 PM, Dino Viehland <dinov at microsoft.com> wrote:
> > My guess is you need to change:
> >
> >>>> shapefile1 = MapWinGIS.Shapefile
> >
> > To:
> >
> >>>> shapefile1 = MapWinGIS.Shapefile()
> >
> > You've just gotten a reference to the class whereas the C# code has
> > created an instance of that class.
> >
> >> -----Original Message-----
> >> From: users-bounces at lists.ironpython.com [mailto:users-
> >> bounces at lists.ironpython.com] On Behalf Of Bruce Bromberek
> >> Sent: Thursday, July 01, 2010 6:22 PM
> >> To: Discussion of IronPython
> >> Subject: [IronPython] Conflicting information with Ironpython and
> >> MapWindowGIS interop
> >>
> >> I'm trying to drive MapWindows GIS from an Ironpython script to
> >> automate some tasks.  MapWindow is in C#, and I have generated the
> >> Interop Assembly, and I can load the MapWinGIS namespace.
> >> Following this example in C#
> >>
> >> //create a new instance for MapWinGIS.Shapefile
> >> //MapWinGIS.Shapefile  is a data provider for ESRI Shapefile
> >> MapWinGIS.Shapefile shapefile1 = new MapWinGIS.Shapefile();
> >> //Define the data source for MapWinGIS.Shapefile instance
> >> shapefile1.Open(@"D:\GISSampleData\base.shp", null );
> >>
> >> So I did the following:
> >> >>> import clr
> >> >>> clr.AddReference('MapWindow.Interfaces')
> >> >>> clr.AddReference('MapWinGeoProc')
> >> >>> clr.AddReference('MapWinUtility')
> >> >>> clr.AddReference('MapWinInterfaces')
> >> >>> clr.AddReference('Interop.MapWinGIS')
> >> >>> import MapWinGIS
> >> >>> shapefile1 = MapWinGIS.Shapefile
> >> >>> help(shapefile1.Open)
> >> Help on method_descriptor:
> >>
> >> Open(...)
> >>     Open(self, str ShapefileName, ICallback cBack) -> bool
> >>
> >> >>> shapefile1.Open(r"G:\DLS\BAB\2010 USPS
> >> GIS\ADC_Layer\ADC_ALBANY_NY_120.shp",None)
> >> Traceback (most recent call last):
> >>   File "<stdin>", line 1, in <module>
> >> TypeError: expected IShapefile, got str
> >>
> >> Not being a C# master, I thought maybe I'm accessing the objects
> >> correctly.  Try again using IShapefile instead of Shapefile and I got
> >> this
> >>
> >> >>> t = MapWinGIS.IShapefile
> >> >>> dir(t)
> >> ['BeginPointInShapefile', 'CacheExtents', 'CanUseSpatialIndex',
> >> 'CdlgFilter', 'CellValue', 'Close', 'CreateNew',
> >> 'CreateNewWithShapeID', 'CreateSpatialIndex', 'Dissolve',
> >> 'EditCellValue', 'EditClear', 'EditDeleteField', 'EditDeleteShape',
> >> 'EditInsertField', 'EditInsertShape', 'EditingShapes', 'EditingTable',
> >> 'EndPointInShapefile', 'ErrorMsg', 'Extents', 'Field', 'FieldByName',
> >> 'FileHandle', 'Filename', 'GenerateLabels', 'GetIntersection',
> >> 'GlobalCallback', 'HasSpatialIndex', 'InvertSelection',
> >> 'IsSpatialIndexValid', 'Key', 'Labels', 'LastErrorCode', 'NumFields',
> >> 'NumSelected', 'NumShapes', 'Open', 'PointInShape',
> >> 'PointInShapefile', 'Projection', 'QuickExtents', 'QuickPoint',
> >> 'QuickPoints', 'QuickQueryInEditMode', 'RefreshExtents',
> >> 'RefreshShapeExtents', 'Resource', 'Save', 'SaveAs', 'SelectAll',
> >> 'SelectByShapefile', 'SelectNone', 'SelectShapes',
> >> 'SelectionDrawingOptions', 'Shape', 'ShapeSelected', 'ShapefileType',
> >> 'SpatialIndexMaxAreaPercent', 'StartEditingShapes',
> >> 'StartEditingTable', 'StopEditingShapes', 'StopEditingTable',
> >> 'UseQTree', 'UseSpatialIndex', '__doc__', '__repr__', 'numPoints']
> >> >>> t.Open.__doc__
> >> 'Open(self, str ShapefileName, ICallback cBack) -> bool'
> >>
> >> >>> a = r"C:\2010 USPS GIS\Shapefiles\ADC ATLANTA GA 303.shp"
> >> >>> t.Open(a,None)
> >> Traceback (most recent call last):
> >>   File "<stdin>", line 1, in <module>
> >> TypeError: expected IShapefile, got str
> >>
> >> Can anyone tell me what I'm missing?
> >>
> >> Thanks.
> >>
> >> Bruce
> >> _______________________________________________
> >> Users mailing list
> >> Users at lists.ironpython.com
> >> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
> > _______________________________________________
> > Users mailing list
> > Users at lists.ironpython.com
> > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
> >
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com



More information about the Ironpython-users mailing list