Shapelib test

View: New views
5 Messages — Rating Filter:   Alert me  

Shapelib test

by Jamie Lahowetz :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I am learning C so humor me. I have a simple script but everytime I run it I get a segmentation fault. Any ideas?

#include <shapefil.h>

int main (void)
{
    const char * shapefile = "/mnt/share/uas/GRRUVI2_uc/
extractor/colorado/fe_2007_08_county";
    SHPHandle handle;
    int entities;
    int type;
    double minbound;
    double maxbound;
   
    printf("%s\n", shapefile);
   
    handle = SHPOpen(shapefile,"rb");
    SHPGetInfo( handle,&entities,&type,&minbound,&maxbound);
   
    SHPClose(handle);
    return 0;
}


--
Jamie Ryan Lahowetz
University of Nebraska - Lincoln
Graduate Student - Geosciences
402.304.0766
jlahowetz@...

_______________________________________________
Shapelib mailing list
Shapelib@...
http://lists.maptools.org/mailman/listinfo/shapelib

Re: Shapelib test

by Frank Warmerdam-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Jamie Lahowetz wrote:

> I am learning C so humor me. I have a simple script but everytime I run
> it I get a segmentation fault. Any ideas?
>
> #include <shapefil.h>
>
> int main (void)
> {
>     const char * shapefile = "/mnt/share/uas/GRRUVI2_uc/
> extractor/colorado/fe_2007_08_county";
>     SHPHandle handle;
>     int entities;
>     int type;
>     double minbound;
>     double maxbound;
>    
>     printf("%s\n", shapefile);
>    
>     handle = SHPOpen(shapefile,"rb");
>     SHPGetInfo( handle,&entities,&type,&minbound,&maxbound);
>    
>     SHPClose(handle);
>     return 0;
> }

Jamie,

The minbound and maxbound arguments need to be pointers to an array of
four values (for the four dimensions possible in a shapefile).

So more like:

...
      double minbound[4];
      double maxbound[4];

      printf("%s\n", shapefile);

      handle = SHPOpen(shapefile,"rb");
      SHPGetInfo( handle,&entities,&type,minbound,maxbound);
...

Best regards,
--
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam@...
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | Geospatial Programmer for Rent

_______________________________________________
Shapelib mailing list
Shapelib@...
http://lists.maptools.org/mailman/listinfo/shapelib

Re: Shapelib test

by Jamie Lahowetz-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thank you very much. It compiled. I would like to print the values of "entities", how do I do that?

On Mon, Apr 27, 2009 at 10:21 PM, Frank Warmerdam <warmerdam@...> wrote:
Jamie Lahowetz wrote:
> I am learning C so humor me. I have a simple script but everytime I run
> it I get a segmentation fault. Any ideas?
>
> #include <shapefil.h>
>
> int main (void)
> {
>     const char * shapefile = "/mnt/share/uas/GRRUVI2_uc/
> extractor/colorado/fe_2007_08_county";
>     SHPHandle handle;
>     int entities;
>     int type;
>     double minbound;
>     double maxbound;
>
>     printf("%s\n", shapefile);
>
>     handle = SHPOpen(shapefile,"rb");
>     SHPGetInfo( handle,&entities,&type,&minbound,&maxbound);
>
>     SHPClose(handle);
>     return 0;
> }

Jamie,

The minbound and maxbound arguments need to be pointers to an array of
four values (for the four dimensions possible in a shapefile).

So more like:

...
     double minbound[4];
     double maxbound[4];

     printf("%s\n", shapefile);

     handle = SHPOpen(shapefile,"rb");
     SHPGetInfo( handle,&entities,&type,minbound,maxbound);
...

Best regards,
--
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam@...
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | Geospatial Programmer for Rent

_______________________________________________
Shapelib mailing list
Shapelib@...
http://lists.maptools.org/mailman/listinfo/shapelib



--
Jamie Ryan Lahowetz
University of Nebraska - Lincoln
Graduate Student - Geosciences
402.304.0766
jlahowetz@...

_______________________________________________
Shapelib mailing list
Shapelib@...
http://lists.maptools.org/mailman/listinfo/shapelib

Re: Shapelib test

by Jamie Lahowetz :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thank you very much. It compiled. I would like to print the values of "entities", how do I do that?

On Mon, Apr 27, 2009 at 10:21 PM, Frank Warmerdam <warmerdam@...> wrote:
Jamie Lahowetz wrote:
> I am learning C so humor me. I have a simple script but everytime I run
> it I get a segmentation fault. Any ideas?
>
> #include <shapefil.h>
>
> int main (void)
> {
>     const char * shapefile = "/mnt/share/uas/GRRUVI2_uc/
> extractor/colorado/fe_2007_08_county";
>     SHPHandle handle;
>     int entities;
>     int type;
>     double minbound;
>     double maxbound;
>
>     printf("%s\n", shapefile);
>
>     handle = SHPOpen(shapefile,"rb");
>     SHPGetInfo( handle,&entities,&type,&minbound,&maxbound);
>
>     SHPClose(handle);
>     return 0;
> }

Jamie,

The minbound and maxbound arguments need to be pointers to an array of
four values (for the four dimensions possible in a shapefile).

So more like:

...
     double minbound[4];
     double maxbound[4];

     printf("%s\n", shapefile);

     handle = SHPOpen(shapefile,"rb");
     SHPGetInfo( handle,&entities,&type,minbound,maxbound);
...

Best regards,
--
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam@...
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | Geospatial Programmer for Rent

_______________________________________________
Shapelib mailing list
Shapelib@...
http://lists.maptools.org/mailman/listinfo/shapelib



--
Jamie Ryan Lahowetz
University of Nebraska - Lincoln
Graduate Student - Geosciences
402.304.0766
jlahowetz@...

_______________________________________________
Shapelib mailing list
Shapelib@...
http://lists.maptools.org/mailman/listinfo/shapelib

Re: Shapelib test

by Frank Warmerdam-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Jamie Lahowetz wrote:
> Thank you very much. It compiled. I would like to print the values of
> "entities", how do I do that?

Jamie,

   printf("entities = %d\n", entities);

With all due respect, this is not shapelib specific, and I'd suggest
you spend some time with a C/C++ book and/or a programming mentor.

Best regards,
--
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam@...
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | Geospatial Programmer for Rent

_______________________________________________
Shapelib mailing list
Shapelib@...
http://lists.maptools.org/mailman/listinfo/shapelib