Hello again!
I have tried to isolate the core of my code. It is quite a few lines so bear
with me.
I get an exception when I call the mitab_c_write_feature method. I does not
happen always, and not even very often but sometimes.
Could this be something wrong with my file. How do I check?
Best Regards
Mikael Larsson
num_fields = mitab_c_get_field_count(input_dataset);
// Iterate through the fields, copying them to the output
for(iFieldNumber = 0; iFieldNumber < num_fields; iFieldNumber++)
{
mitab_c_add_field(output_dataset,
mitab_c_get_field_name(input_dataset, iFieldNumber),
mitab_c_get_field_type(input_dataset, iFieldNumber),
mitab_c_get_field_width(input_dataset, iFieldNumber),
mitab_c_get_field_precision(input_dataset, iFieldNumber), 0, 0);
}
int num_parts,nStat,nOldStat=0;
// Now for all features in the source file....
int iNumberObjects = 0; // To hold the number of features transformed
for( input_feature_id = mitab_c_next_feature_id(input_dataset,-1);
input_feature_id != -1;
input_feature_id = mitab_c_next_feature_id(input_dataset,input_feature_id) )
{
mitab_feature input_feature;
mitab_feature output_feature;
// Read next feature object
input_feature = mitab_c_read_feature(input_dataset, input_feature_id);
if(input_feature == NULL)
{
char buffer[20];
_itoa( input_feature_id, buffer, 10 );
CString strFeatureNumber(buffer);
strLogg = strLogg + "När objekt nummer " + strFeatureNumber + "
skulle läsas från tabellen uppstod ett fel. Objektet verkar vara tomt.\r\n";
continue;
}
// Create output feature
output_feature = mitab_c_create_feature(output_dataset,
mitab_c_get_type(input_feature));
if(output_feature == NULL)
{
char buffer[20];
_itoa( input_feature_id, buffer, 10 );
CString strFeatureNumber(buffer);
strLogg = strLogg + "När objekt nummer " + strFeatureNumber + "
skulle läsas från tabellen uppstod ett fel. Objektet verkar vara tomt.\r\n";
// Destroy the feature object
mitab_c_destroy_feature(output_feature);
mitab_c_destroy_feature(input_feature);
continue;
}
int iFeatureType = mitab_c_get_type(input_feature);
if(iFeatureType == 6)
{
strLogg = strLogg + "Varning! Ett objekt av typen: Båge har
påträffats. Detta objekt kan inte transformeras och kommer att hoppas
över.\r\n";
if(!stSTTrans->bSilent)
{
wndProgress.SetLoggText(strLogg);
}
// Destroy the feature object
mitab_c_destroy_feature(output_feature);
mitab_c_destroy_feature(input_feature);
continue;
}
if(iFeatureType == 8)
{
strLogg = strLogg + "Varning! Ett objekt av typen: Rektangel har
påträffats. Detta objekt kan inte transformeras och kommer att hoppas
över.\r\n";
if(!stSTTrans->bSilent)
{
wndProgress.SetLoggText(strLogg);
}
// Destroy the feature object
mitab_c_destroy_feature(output_feature);
mitab_c_destroy_feature(input_feature);
continue;
}
if(iFeatureType == 9)
{
strLogg = strLogg + "Varning! Ett objekt av typen: Elips har
påträffats. Detta objekt kan inte transformeras och kommer att hoppas
över.\r\n";
if(!stSTTrans->bSilent)
{
wndProgress.SetLoggText(strLogg);
}
// Destroy the feature object
mitab_c_destroy_feature(output_feature);
mitab_c_destroy_feature(input_feature);
continue;
}
// Set the feature symbol properties
// Only valid for point and multipoint
if(iFeatureType == 1 || iFeatureType == 10)
{
mitab_c_set_symbol(output_feature,
mitab_c_get_symbol_no(input_feature), mitab_c_get_symbol_size(input_feature),
mitab_c_get_symbol_color(input_feature));
}
// Set the feature text properties
// Only vaild for text
// Also set the text itself
if(iFeatureType == 4)
{
mitab_c_set_text_display(output_feature,
mitab_c_get_text_angle(input_feature),
mitab_c_get_text_height(input_feature),
mitab_c_get_text_width(input_feature),
mitab_c_get_text_fgcolor(input_feature),
mitab_c_get_text_bgcolor(input_feature),
mitab_c_get_text_justification(input_feature),
mitab_c_get_text_spacing(input_feature),
mitab_c_get_text_linetype(input_feature));
mitab_c_set_text(output_feature, mitab_c_get_text(input_feature));
}
// Set the feature brush properties
// Applies to region, ellipse and rectangle objects
if(iFeatureType == 7 || iFeatureType == 8)
{
mitab_c_set_brush(output_feature,
mitab_c_get_brush_fgcolor(input_feature),
mitab_c_get_brush_bgcolor(input_feature),
mitab_c_get_brush_pattern(input_feature),
mitab_c_get_brush_transparent(input_feature));
}
// Set the feature font properties
// Only valid for TABFC_Text or TABFC_FontPoint
if(iFeatureType == 2 || iFeatureType == 4)
{
mitab_c_set_symbol(output_feature,
mitab_c_get_symbol_no(input_feature), mitab_c_get_symbol_size(input_feature),
mitab_c_get_symbol_color(input_feature));
mitab_c_set_symbol_angle(output_feature,
mitab_c_get_text_angle(input_feature));
mitab_c_set_font(output_feature, mitab_c_get_font(input_feature));
mitab_c_set_fontstyle(output_feature,
mitab_c_get_fontstyle(input_feature, bolIsMIF), bolIsMIF);
}
// Set the feature pen properties
// Only valid for polyline, region, rectangle, arc and ellipse objects
if(iFeatureType == 5 || iFeatureType == 7 || iFeatureType == 8)
{
mitab_c_set_pen(output_feature,
mitab_c_get_pen_width(input_feature),
mitab_c_get_pen_pattern(input_feature),
mitab_c_get_pen_color(input_feature));
}
// Read the feature attributes
for(iFieldNumber = 0; iFieldNumber < num_fields; iFieldNumber++)
{
mitab_c_set_field(output_feature, iFieldNumber,
mitab_c_get_field_as_string(input_feature, iFieldNumber));
}
bool bOnePointPolyline = false;
for(int partno = 0; partno < num_parts; partno++)
{
int num_points = mitab_c_get_vertex_count(input_feature, partno);
if(num_points == 1 && iFeatureType == 5)
{
bOnePointPolyline = true;
break;
}
int iValidPoints = 0;
int iInValidPoints = 0;
for(int pointno = 0; pointno < num_points; pointno++)
{
if(pointno >= m_allocSize)
{
m_allocSize = m_allocSize + 25;
m_dblXInputCoord = (double *)
realloc(m_dblXInputCoord,m_allocSize*sizeof(double));
m_dblYInputCoord = (double *)
realloc(m_dblYInputCoord,m_allocSize*sizeof(double));
}
bValidCoord = TransformOne(stSTTrans,
inSystemStruct,
utSystemStruct,
mitab_c_get_vertex_x(input_feature,
partno, pointno),
mitab_c_get_vertex_y(input_feature,
partno, pointno),
&m_dblXInputCoord[pointno],
&m_dblYInputCoord[pointno]);
}
mitab_c_set_points(output_feature, partno, num_points,
m_dblXInputCoord, m_dblYInputCoord);
}
if(bOnePointPolyline)
{
strLogg = strLogg + "Varning! En polyline med endast en punkt har
påträffats. Objektet har ignorerats i transformationen.\r\n";
if(!stSTTrans->bSilent)
{
wndProgress.SetLoggText(strLogg);
}
// Destroy the feature object
mitab_c_destroy_feature(output_feature);
mitab_c_destroy_feature(input_feature);
continue;
}
// Fails here...
mitab_c_write_feature(output_dataset, output_feature);
// Destroy the feature object
mitab_c_destroy_feature(output_feature);
mitab_c_destroy_feature(input_feature);
iNumberObjects++;
m_allocSize = 25;
m_dblXInputCoord = (double *)
realloc(m_dblXInputCoord,m_allocSize*sizeof(double));
m_dblYInputCoord = (double *)
realloc(m_dblYInputCoord,m_allocSize*sizeof(double));
}
// Close input and output file
mitab_c_close(input_dataset);
mitab_c_close(output_dataset);
To: [email protected]
From: [EMAIL PROTECTED]
Date: Tue, 21 Oct 2008 16:58:27 -0700
Subject: RE: [mitab] catching exceptions from the mitab library.
And here's the minimal example to create a TAB file. It seems as
though you have to have at least one field for Mitab to output a valid TAB file
that MapInfo can read!
mitab_handle hTAB = mitab_c_create("C:\\tmp\\test.tab","tab","CoordSys Earth
Projection 1, 0",-32.0,-34.0,152.0,150.0);
if (hTAB!=NULL)
{
int nField = mitab_c_add_field(hTAB,"Test",TABFT_Integer,0,0,0,0);
double xs[1];
double ys[1];
xs[0] = 151.0; ys[0] = -33.0;
mitab_feature hFeature;
hFeature = mitab_c_create_feature(hTAB,TABFC_Point);
mitab_c_set_field(hFeature,nField,"1");
mitab_c_set_points(hFeature,0,1,xs,ys);
mitab_c_write_feature(hTAB,hFeature);
mitab_c_destroy_feature(hFeature);
xs[0] = 151.1; ys[0] = -33.1;
hFeature = mitab_c_create_feature(hTAB,TABFC_Point);
mitab_c_set_field(hFeature,nField,"2");
mitab_c_set_points(hFeature,0,1,xs,ys);
mitab_c_write_feature(hTAB,hFeature);
mitab_c_destroy_feature(hFeature);
}
mitab_c_close(hTAB);
--- On Tue, 21/10/08, Mikael Larsson <[EMAIL PROTECTED]> wrote:
From: Mikael Larsson <[EMAIL PROTECTED]>
Subject: RE: [mitab] catching exceptions from the mitab library.
To: [email protected]
Received: Tuesday, 21 October, 2008, 5:55 AM
Yes, but that does not work for me.
I never enter the catch-part, I still get a crash on the same line of code.
To: [EMAIL PROTECTED] com
From: [EMAIL PROTECTED] .com
Date: Mon, 20 Oct 2008 14:42:29 -0700
Subject: Re: [mitab] catching exceptions from the mitab library.
Have you tried adding a try { .... } catch (..) { } block around the call that
crashes ?
--- On Sun, 19/10/08, Mikael Larsson <[EMAIL PROTECTED] com> wrote:
From: Mikael Larsson <[EMAIL PROTECTED] com>
Subject: [mitab] catching exceptions from the mitab library.
To: [EMAIL PROTECTED] com
Received: Sunday, 19 October, 2008, 9:52 PM
Hello!
I'm writing a software to convert a file from one coordinate system to another.
I do this by reading the different objects from the file with the available
functions, transform the coordinates and write back the object to a new output
file.
For one input file I get an exception when calling the mitab_c_write_ feature
function. The exception originates in the function PickSeedsForSplit found in
the file mitab_mapindexblock .cpp. The problem seems to be that nSrcHeight or
nSrcWidth can be equal to zero. Then the division on line 1065 will not work
and an exception is thrown.
Is there any way to catch this exception in my MFC application? I would very
much like to avoid a software crash because of this.
I'm using the latest version (1.7.0).
Can anyone please advise?
Best Regards
Mikael Larsson
Connect to the next generation of MSN Messenger Get it now!
Send instant messages to your online friends http://au.messenger .yahoo.com
Explore the seven wonders of the world Learn more!
Make the switch to the world's best email.
Get Yahoo!7 Mail.
_________________________________________________________________
Connect to the next generation of MSN Messenger
http://imagine-msn.com/messenger/launch80/default.aspx?locale=en-us&source=wlmailtagline