Geo-OGC-Service-WFS
view release on metacpan or search on metacpan
lib/Geo/OGC/Service/WFS.pm view on Meta::CPAN
$writer->element(import => {
namespace => "http://www.opengis.net/gml",
schemaLocation => "http://schemas.opengis.net/gml/2.1.2/feature.xsd" });
for my $name (sort keys %types) {
my $type = $types{$name};
# to do: geometry and primary key
my ($pseudo_credentials) = pseudo_credentials($type);
my @elements;
for my $property (keys %{$type->{columns}}) {
next if $pseudo_credentials->{$property};
my $minOccurs = 0;
push @elements, ['element', {
name => $type->{columns}{$property}{out_name},
type => $type->{columns}{$property}{out_type},
minOccurs => "$minOccurs",
maxOccurs => "1"
}];
}
lib/Geo/OGC/Service/WFS.pm view on Meta::CPAN
if ($query->{BBOX}) {
@bbox = @{$query->{BBOX}};
$bbox_crs = 4326; # WFS 1.1.0 14.3.3
if (@bbox == 5) {
$bbox_crs = epsg_number(pop @bbox);
}
}
my $filter = filter2sql($query->{filter}, $type) // '';
# pseudo_credentials: these fields are required to be in the filter and they are not included as attributes
my ($pseudo_credentials, @pseudo_credentials) = pseudo_credentials($type);
if (@pseudo_credentials) {
# test for pseudo credentials in filter
my $pat1 = "\\(\\(\"$pseudo_credentials[0]\" = '.+?'\\) AND \\(\"$pseudo_credentials[1]\" = '.+?'\\)\\)";
my $pat2 = "\\(\\(\"$pseudo_credentials[1]\" = '.+?'\\) AND \\(\"$pseudo_credentials[0]\" = '.+?'\\)\\)";
my $n = join(' and ', @pseudo_credentials);
unless ($filter and ($filter =~ /$pat1/ or $filter =~ /$pat2/)) {
$self->error({ exceptionCode => 'InvalidParameterValue',
locator => 'filter',
ExceptionText => "Not authorized. Please provide '$n' in filter." });
return;
}
}
my @columns = ("$type->{'gml:id'} as gml_id");
# reverse the field names
for my $column (keys %{$type->{columns}}) {
next if $pseudo_credentials->{$column};
my $name = $type->{columns}{$column}{out_name};
next if $query->{properties} && not $query->{properties}{$name};
$filter =~ s/$name/$column/g if $filter;
push @columns, "\"$column\" as \"$name\"";
}
my $Geometry = $type->{GeometryColumn};
push @columns, "ST_Transform($Geometry,$epsg) as geometryProperty";
my $sql = "SELECT ".join(',',@columns)." FROM $type->{Table} WHERE ST_IsValid($Geometry)";
lib/Geo/OGC/Service/WFS.pm view on Meta::CPAN
Abstract => "Layer from $table->[1] in $table->[0] using column $geom.",
DefaultSRS => $geometries{$geom}[0].":".$geometries{$geom}[1],
SRID => $geometries{$geom}[1],
DataSource => $ds,
Table => $table->[2], # full quoted name with schema
GeometryColumn => '"'.$geom.'"',
columns => \%columns,
'gml:id' => $pk[0],
Operations => $type->{Operations}, # $self->{config}{Operations} is the default
require_user => $type->{require_user} // $self->{config}{require_user}, # operation dependent?
pseudo_credentials => $type->{pseudo_credentials},
# to do: these in ows:WGS84BoundingBox, GetCapabilities
#LowerCorner
#UpperCorner
};
for my $o (@GDAL_GML_Creation_options) {
$feature_type->{$o} = $type->{$o} if exists $type->{$o};
}
my ($h, @c) = pseudo_credentials($feature_type);
my $ok = 1;
for my $c (@c) {
unless ($feature_type->{columns}{$c}) {
carp "pseudo credential column '$c' not in table.\n";
$ok = 0;
next;
}
}
next unless $ok;
push @types, $feature_type;
lib/Geo/OGC/Service/WFS.pm view on Meta::CPAN
sub list2element {
my ($tag, $list) = @_;
my @element;
my @t = split /\s*,\s*/, $list;
for my $t (@t) {
push @element, [$tag, $t];
}
return @element;
}
sub pseudo_credentials {
my $type = shift;
my $c = $type->{pseudo_credentials};
return ({}) unless $c;
my($c1,$c2) = $c =~ /(\w+),(\w+)/;
return ({$c1 => 1,$c2 => 1},$c1,$c2);
}
sub min {
my $retval = shift;
for my $x (@_) {
next unless defined $x;
$retval = $x unless defined $retval;
t/postgis.t view on Meta::CPAN
"debug" => "0",
"Title" => "Test WFS",
"Operations" => "Query,Insert,Update,Delete",
"FeatureTypeList" => [
{
"prefix" => "local",
"gml:id" => "id",
"DataSource" => "PG:dbname=$test_db host=localhost user=$user password=$pass",
"test_auth.geom" => {
"Operations" => "Query,Insert,Update,Delete",
"pseudo_credentials" => "usern,pass"
}
}
]
};
my $app = Geo::OGC::Service->new({ config => $config, services => { WFS => 'Geo::OGC::Service::WFS' }})->to_app;
test_psgi $app, sub {
my $cb = shift;
my $req = HTTP::Request->new(POST => "/");
t/postgis.t view on Meta::CPAN
};
if ($@) {
is $@, 0, 'Transaction Delete';
} else {
$pp->pretty_print($dom);
#say STDERR $dom->toString;
is 1, 1, 'Transaction Delete';
}
};
# test pseudo credentials
for my $sql (
"create table test_auth (id serial primary key, usern text, pass text)",
"SELECT AddGeometryColumn ('public','test_auth','geom',4326,'POINT',2)",
"insert into test_auth (usern, pass, geom) values ('me', 'pass', ST_GeomFromText('POINT (1 2)', 4326))",
"insert into test_auth (usern, pass, geom) values ('me', 'pass', ST_GeomFromText('POINT (3 4)', 4326))",
"insert into test_auth (usern, pass, geom) values ('her', 'pass', ST_GeomFromText('POINT (3 4)', 4326))"
)
{
$dbh->do($sql) or die $dbh->errstr;
( run in 0.246 second using v1.01-cache-2.11-cpan-4d50c553e7e )