geojson#GeoJSON TypeScript Examples
The following examples show how to use
geojson#GeoJSON.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: data-utils.ts From prism-frontend with MIT License | 7 votes |
// get the first coordinate in a GeoJSON
export function coordFirst(data: GeoJSON): number[] {
if (data.type === 'FeatureCollection') {
return coordFirst(data.features[0].geometry);
}
if (data.type === 'Feature') {
return coordFirst(data.geometry);
}
if (data.type === 'GeometryCollection') {
return coordFirst(data.geometries[0]);
}
if (data.type === 'MultiPolygon') {
return data.coordinates[0][0][0];
}
if (data.type === 'Polygon') {
return data.coordinates[0][0];
}
throw new Error(
'you called coordFirst on data that is not a GeoJSON or GeoJSON Geometry',
);
}
Example #2
Source File: upload-hobo-data.ts From aqualink-app with MIT License | 6 votes |
handleEntityDuplicate = <T>(
repository: Repository<T>,
query: (
repository: Repository<T>,
polygon?: GeoJSON | null,
) => Promise<T | undefined>,
polygon?: GeoJSON | null,
) => {
return (err) => {
// Catch unique violation, i.e. there is already a site at this location
if (err.code === '23505') {
return query(repository, polygon).then((found) => {
if (!found) {
throw new InternalServerErrorException(
'Could not fetch conflicting entry',
);
}
return found;
});
}
throw err;
};
}
Example #3
Source File: upload-hobo-data.ts From aqualink-app with MIT License | 6 votes |
poiQuery = (
poiRepository: Repository<SiteSurveyPoint>,
polygon?: GeoJSON | null,
) => {
return poiRepository
.createQueryBuilder(`surveyPoints`)
.innerJoinAndSelect('surveyPoints.site', 'site')
.where(
`surveyPoints.polygon = ST_SetSRID(ST_GeomFromGeoJSON(:polygon), 4326)::geometry`,
{ polygon },
)
.getOne();
}
Example #4
Source File: upload-hobo-data.ts From aqualink-app with MIT License | 6 votes |
siteQuery = (
siteRepository: Repository<Site>,
polygon?: GeoJSON | null,
) => {
return siteRepository
.createQueryBuilder(`entity`)
.where(
`entity.polygon = ST_SetSRID(ST_GeomFromGeoJSON(:polygon), 4326)::geometry`,
{ polygon },
)
.getOne();
}
Example #5
Source File: users.spec.ts From aqualink-app with MIT License | 6 votes |
createUserDto = (mockUser: DeepPartial<User>): CreateUserDto => ({
fullName: mockUser.fullName,
email: mockUser.email as string,
organization: mockUser.organization,
country: mockUser.country,
description: mockUser.description,
imageUrl: mockUser.imageUrl,
location: mockUser.location as GeoJSON,
})
Example #6
Source File: users.entity.ts From aqualink-app with MIT License | 6 votes |
@ApiPointProperty()
@Column({
type: 'geometry',
spatialFeatureType: 'Point',
nullable: true,
srid: 4326,
})
@Index({ spatial: true })
location: GeoJSON | null;
Example #7
Source File: sites.entity.ts From aqualink-app with MIT License | 6 votes |
@ApiPointProperty()
@Column({
type: 'geometry',
unique: true,
srid: 4326,
nullable: false,
})
@Index({ spatial: true })
polygon: GeoJSON | null;
Example #8
Source File: site-survey-points.service.ts From aqualink-app with MIT License | 6 votes |
async update(
id: number,
updateSiteSurveyPointDto: UpdateSiteSurveyPointDto,
): Promise<SiteSurveyPoint> {
const { latitude, longitude, siteId } = updateSiteSurveyPointDto;
const polygon: { polygon: GeoJSON } | {} =
longitude !== undefined && latitude !== undefined
? {
polygon: createPoint(longitude, latitude),
}
: {};
const updateSite = siteId !== undefined ? { site: { id: siteId } } : {};
const result = await this.surveyPointsRepository.update(id, {
...omit(updateSiteSurveyPointDto, 'longitude', 'latitude', 'siteId'),
...updateSite,
...polygon,
});
if (!result.affected) {
throw new NotFoundException(
`Site Point of Interest with ID ${id} not found.`,
);
}
const updated = await this.surveyPointsRepository.findOne(id);
return updated!;
}
Example #9
Source File: site-survey-points.service.ts From aqualink-app with MIT License | 6 votes |
async create(
createSiteSurveyPointDto: CreateSiteSurveyPointDto,
): Promise<SiteSurveyPoint> {
const { latitude, longitude, siteId } = createSiteSurveyPointDto;
const polygon: GeoJSON | undefined =
longitude !== undefined && latitude !== undefined
? createPoint(longitude, latitude)
: undefined;
return this.surveyPointsRepository.save({
...createSiteSurveyPointDto,
site: { id: siteId },
polygon,
});
}
Example #10
Source File: site-survey-points.entity.ts From aqualink-app with MIT License | 6 votes |
@ApiPointProperty()
@Column({
type: 'geometry',
unique: true,
srid: 4326,
nullable: true,
})
@Index({ spatial: true })
polygon: GeoJSON | null;
Example #11
Source File: regions.entity.ts From aqualink-app with MIT License | 6 votes |
@ApiPointProperty()
@Column({
type: 'geometry',
unique: true,
srid: 4326,
nullable: false,
})
@Index({ spatial: true })
polygon: GeoJSON | null;
Example #12
Source File: video-streams.entity.ts From aqualink-app with MIT License | 5 votes |
@Column('point')
@Index({ spatial: true })
location: GeoJSON;
Example #13
Source File: create-user.dto.ts From aqualink-app with MIT License | 5 votes |
@ApiPointProperty()
@IsOptional()
@IsNotEmpty()
readonly location?: GeoJSON | null;
Example #14
Source File: sensors.service.ts From aqualink-app with MIT License | 5 votes |
async findSensors(): Promise<
(Site & { sensorPosition: GeoJSON; sensorType: SensorType })[]
> {
const sites = await this.siteRepository.find({
where: { sensorId: Not(IsNull()) },
});
// Get spotter data and add site id to distinguish them
const spotterData = await Bluebird.map(
sites,
(site) => {
if (site.sensorId === null) {
console.warn(`Spotter for site ${site.id} appears null.`);
}
return getSpotterData(site.sensorId!).then((data) => {
return {
id: site.id,
...data,
};
});
},
{ concurrency: 10 },
);
// Group spotter data by site id for easier search
const siteIdToSpotterData: Record<number, SpotterData & { id: number }> =
keyBy(spotterData, (o) => o.id);
// Construct final response
return sites.map((site) => {
const data = siteIdToSpotterData[site.id];
const longitude = getLatestData(data.longitude)?.value;
const latitude = getLatestData(data.latitude)?.value;
const sitePosition = site.polygon as Point;
// If no longitude or latitude is provided by the spotter fallback to the site coordinates
return {
...site,
applied: site.applied,
sensorPosition: createPoint(
longitude || sitePosition.coordinates[0],
latitude || sitePosition.coordinates[1],
),
sensorType: SensorType.SofarSpotter,
};
});
}
Example #15
Source File: update-region.dto.ts From aqualink-app with MIT License | 5 votes |
@ApiPointProperty()
@IsOptional()
@IsNotEmpty()
readonly polygon?: GeoJSON;
Example #16
Source File: create-region.dto.ts From aqualink-app with MIT License | 5 votes |
@ApiPointProperty()
@IsNotEmpty()
readonly polygon: GeoJSON;
Example #17
Source File: alerts.entity.ts From prism-frontend with MIT License | 5 votes |
@Column({
type: 'jsonb',
nullable: true,
})
zones?: GeoJSON;