ThinkGeo.com    |     Blog    |     Wiki    |     Support

CAD File Reading Difficulties

Hi,

We have been having trouble with using CAD files (CadFeatureLayer) in our projects. One we are seeing a lot is an exception when getting the bounding box.

            featureSource.Open();
            bounds = featureSource.GetBoundingBox();
            featureSource.Close();

gives:

 Exception thrown: 'System.Reflection.TargetInvocationException' in mscorlib.dll
'Pear GIS.exe' (CLR v4.0.30319: Pear GIS.exe): Loaded 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\PrivateAssemblies\Runtime\Microsoft.VisualStudio.Debugger.Runtime.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentOutOfRangeException: The input double value is out of range.
Parameter name: degreeAngle
   at CadDumper.DwgDxfCadDumper.Dump()
   at CadDumper.CadDumper.GetCadFeatures()
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at ThinkGeo.MapSuite.Layers.CadFeatureSource.5ko=(String cadPathFilename)
   at ThinkGeo.MapSuite.Layers.CadFeatureSource.40o=()
   at ThinkGeo.MapSuite.Layers.CadFeatureSource.GetAllFeaturesCore(IEnumerable`1 returningColumnNames)
   at ThinkGeo.MapSuite.Layers.FeatureSource.GetBoundingBoxCore()
   at ThinkGeo.MapSuite.Layers.FeatureSource.GetBoundingBox()
   at enzo.PearProjection.ProjectionHelper.OutOfBounds(FeatureSource featureSource, Double eastingLimit, Double northingLimit) in C:\Users\User\Source\Workspaces\Pear Technology\Enzo\enzo\Projection\ProjectionHelper.cs:line 85

I believe the files are georeferenced for the UK national grid (OSGB) and the units are mm.

Another place where the same files give an exception is:

  cfl.Open();
  Features = cfl.QueryTools.GetAllFeatures(ReturningColumnsType.AllColumns);

Gives:

System.NullReferenceException: Object reference not set to an instance of an object.
   at enzo.Importing.CadImporter..ctor(String filePath, String layerName) in C:\Users\User\Source\Workspaces\Pear Technology\Enzo\enzo\Importing\CadImporter.cs:line 38

I hope you can help with these couple of exceptions and look forwrad to hearing from you soon.

Regards,
Jonathan

Hi Jonathan,

From the exception information, it looks the first exception is “degreeAngle” out of range, I think your file maybe decimal degree but not meter, please check that and set the map unit equal it.

The 2nd one looks like one of your parameter is null, I am not sure whether the filePath and layerName is OK, please check your parameters.

If you still met the same exception, could you please provide us the same project and sample data so we can reproduce it?

Regards,

Ethan

Hi Ethan,

Thanks for the suggestions. I have been told it’s in mm, do you know how I could check?

That said I have just tried setiting the projection to WGS84 using a PRJ file and the following:

                    layer.FeatureSource.Projection = new Proj4Projection
                    {
                        InternalProjectionParametersString = Proj4Projection.ConvertPrjToProj4(prjDefinitiion),
                        ExternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(27700)
                    };

where prjDefinition is the text read from a .PRJ file, like:

GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]

and still get the same exception if try to do a GetBoundingBox. So I’m thinking there is something else not quite right?

Oh and also, filepath and layername are not null.

Regards,
Jonathan

Hi again Ethan,

We also tried it on the standard ThinkGEO CAD sample project and get the error there as well. I can send the DXF/DWF file(s).

Jonathan

By the way, if I send in this forum are the files made public? They are not really sensitive, but are from a customer, so it would be better if I could send direct?

Hi Jonathan,

About upload file:

If the file is not so big, you can upload that in one ticket.

If the file is big, you can contact your sales to get the FTP account and then upload to the FTP.

About the projection:

Our map don’t have the unit MM(millimeter?) and we only have DecimalDegree, Meter, Feet on map.

The projection definition means 4326, so if you met exception when get bouding box, you can try to get that before reprojection (under 4326), then convert the result into 27700.

Beside that I need to view your project code to make sure whether your render code is correct.

Regards,

Ethan

Hi Ethan,

Thanks for the suggestion of a ticket - I have sent the CAD files that way. I have not sent any project as they fail in the standard downloadable thinkgeo sample project - so you would have that anyway. Good point about the units, however I have had other files in mm that have been OK as I have a custom class called RescaleProjection based on Projection to rescale as required. The file we have been talking about falls over before doing any rescaling / reprojecting.

Regards,
Jonathan

Hi Jonathan,

Thanks for upload your data.

We will look into it and reply you in your ticket.

Regards,

Ethan