PrePAN

Sign in to PrePAN

Geo::Index Geographic indexer

Good

Synopsis

use Geo::Index;

@points = ( { lat =>   1.0, lon =>   2.0 }, 
            { lat => -90.0, lon =>   0.0, name => 'South Pole' }, 
            { lat =>  30.0, lon => -20.0, ele => 123.4 } );
$point = { lat => 10.0, lon => 20.0 };

$index = Geo::Index->new();
$index->IndexPoints( \@points );
$index->Index( $point );
$index->Index( [ 30, 40 ] );

%search_options = ( sort_results => 1, radius=>5_000_000 );
$results = $index->Search( [ -80, 20 ], \%search_options );
print "$$results[0]{name}\n";  # Prints 'South Pole'

# Get all points in the southern hemisphere
$results = $index->SearchByBounds( [ -180, -90, 180, 0 ] );
print "$$results[0]{name}\n";  # Also prints 'South Pole'

($closest) = $index->Closest( [ -80, 20 ] );
print "$$closest{name}\n";     # Also prints 'South Pole'

($closest) = $index->Closest( $points[1], { post_condition=>'NONE' } );
print "$$closest{name}\n";     # Also prints 'South Pole'

($farthest) = $index->Farthest( [ 90, 0 ] );
print "$$farthest{name}\n";    # Also prints 'South Pole'

# Full sample code and details on additional methods can be found in the documentation 
# and in the "examples" directory.

Description

Geo::Index is a module for creating in-memory geographic point indices. Once indexed, fast searches can be run. The module supports search by radius, by bounding box and by proximity.

This will be my first CPAN release so I welcome any feedback you might have. The module has full documentation and test cases. Have I missed anything?

As of v0.0.4 XS is being used directly instead of via Inline::C. Can anyone comment on whether the way I wrote the XS support code is correct for use in a module?


The following was in regards to v0.0.3:

One specific thing that I'd value feedback on is my use of Inline::C. My code does have automatic fallbacks in place for when C isn't available and includes instructions for using it (the C code) in a server environment. Is there anything else I should be aware of when using it in a module?

Thanks!

Comments

You could just make the whole thing a proper XS module rather than using Inline::C

https://metacpan.org/pod/InlineX::C2XS could help you to do that if you're not confident doing it yourself. I've used it myself with C++.

Personally I think if you're putting something on cpan either go with pure perl or make it XS, don't have it compile at runtime.
Per your suggestion I went the XS route. Much cleaner and more robust now
anonymouse
Anonymous
perl style generally avoids CamelCase naming in favor of snake_case, so ->index_points is more perlish than ->IndexPoints.
@Anonymous: There's a certain wonderful irony to that statement... :^)

Please sign up to post a review.