Various PHP code for processing geometry